tests/thread/stress_schedule.py: Assign globals before running test.

When threading is enabled without the GIL then there can be races between
the threads accessing the globals dict.  Avoid this issue by making sure
all globals variables are allocated before starting the threads.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2020-10-28 00:54:30 +11:00
parent 05f95682e7
commit 368c1a0961
1 changed files with 4 additions and 3 deletions

View File

@ -14,7 +14,11 @@ except AttributeError:
gc.disable()
_NUM_TASKS = 10000
_TIMEOUT_MS = 10000
n = 0 # How many times the task successfully ran.
t = None # Start time of test, assigned here to preallocate entry in globals dict.
def task(x):
@ -34,9 +38,6 @@ def thread():
for i in range(8):
_thread.start_new_thread(thread, ())
_NUM_TASKS = const(10000)
_TIMEOUT_MS = const(10000)
# Wait up to 10 seconds for 10000 tasks to be scheduled.
t = utime.ticks_ms()
while n < _NUM_TASKS and utime.ticks_diff(utime.ticks_ms(), t) < _TIMEOUT_MS: