zephyr/arch
Alberto Escolar Piedras fece6907b4 arch: POSIX: Fix race with unused threads
Fix a race which seems to have been presenting itself
very sporadically on loaded systems.
The race seems to have caused tests/kernel/sched/schedule_api
to fail at random on native_posix.

The case is a bit convoluted:
When the kernel calls z_new_thread(), the POSIX arch saves
the new thread entry call in that new Zephyr thread stack
together with a bit of extra info for the POSIX arch.
And spawns a new pthread (posix_thread_starter()) which
will eventually (after the Zephyr kernel swapped to it),
call that entry function.
(Note that in principle a thread spawned by pthreads may
be arbitrarily delayed)
The POSIX arch does not try to synchronize to that new
pthread (because why should it) until the first time the
Zephyr kernel tries to swap to that thread.
But, the kernel may never try to swap to it.
And therefore that thread's posix_thread_starter() may never
have got to run before the thread was aborted, and its
Zephyr stack reused for something else by the Zephyr app.

As posix_thread_starter() was relaying on looking into that
thread stack, it may now be looking into another thread stack
or anything else.

So, this commit fixes it by having posix_thread_starter()
get the input it always needs not from the Zephyr stack,
but from its own pthread_create() parameter pointing to a
structure kept by the POSIX arch.

Note that if the thread was aborted before reaching that point
posix_thread_starter() will NOT call the Zephyr thread entry
function, but just cleanup.

With this change all "asynchronous" parts of the POSIX arch
should relay only on the POSIX arch own structures.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-07-19 11:37:34 +02:00
..
arc arch: arc: build cache.c conditionally 2019-07-04 10:04:27 -04:00
arm arch: arm: cleanup workaround for QEMU Cortex-M3 2019-07-17 09:14:44 -07:00
common cleanup: include/: move misc/__assert.h to sys/__assert.h 2019-06-27 22:55:49 -04:00
nios2 cleanup: include/: move misc/util.h to sys/util.h 2019-06-27 22:55:49 -04:00
posix arch: POSIX: Fix race with unused threads 2019-07-19 11:37:34 +02:00
riscv32 cleanup: include/: move misc/util.h to sys/util.h 2019-06-27 22:55:49 -04:00
x86 x86: allow user mode to induce kernel oops 2019-07-16 18:09:49 -07:00
x86_64 cleanup: include/: move tracing.h to debug/tracing.h 2019-06-27 22:55:49 -04:00
xtensa cleanup: include/: move misc/util.h to sys/util.h 2019-06-27 22:55:49 -04:00
CMakeLists.txt license: cleanup: add SPDX Apache-2.0 license identifier 2019-04-07 08:45:22 -04:00
Kconfig x86_64: minimally preparing for enabling newlib 2019-06-27 16:08:32 -04:00