diff options
| author | Damien George <damien@micropython.org> | 2020-10-28 00:54:30 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2020-10-28 00:54:30 +1100 |
| commit | 368c1a09611f2a139c0e401eeb4359f9cc2a7c57 (patch) | |
| tree | 9e6252c8f0481c2fc57378dfb6796d0291214cb9 /tests/thread/stress_schedule.py | |
| parent | 05f95682e7ddfb08c317e83826df9a1d636676f3 (diff) | |
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>
Diffstat (limited to 'tests/thread/stress_schedule.py')
| -rw-r--r-- | tests/thread/stress_schedule.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/thread/stress_schedule.py b/tests/thread/stress_schedule.py index c5a402b3a..8be7f2d73 100644 --- a/tests/thread/stress_schedule.py +++ b/tests/thread/stress_schedule.py @@ -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: |
