1.0.25.29: thread state visibility and synchronization
commit409fcc671231b594ec010adf683f72a871ec1d6a
authorGabor Melis <mega@hotpop.com>
Mon, 16 Feb 2009 21:44:11 +0000 (16 21:44 +0000)
committerGabor Melis <mega@hotpop.com>
Mon, 16 Feb 2009 21:44:11 +0000 (16 21:44 +0000)
tree218f89da0f1ae8838f96b20d0229a2aff1c48d0a
parent1d33d240c6f1385157c7d71f681911f7387ddf32
1.0.25.29: thread state visibility and synchronization

C does not guarantee that changes made to a volatile variable in one
thread are visibile to other threads. Use locking primitives (that
have memory barrier semantics) for that purpose.

Thus, all_threads need not be volatile: it's always accessed while
holding all_threads_lock. Thread state does not need volatile either,
as signal a handlers don't change it (save for sig_stop_for_gc_handler
but that sets it restores its value). But visibility issues can arise
and potentially deadlock in stop_the_world, so the thread state is
given a lock. And to reduce busy looping while waiting for the state
to change to STATE_SUSPENDED a condition variable is added as well.

Also convert sig_stop_for_gc_handler to use
wait_for_thread_state_change which frees up SIG_RESUME_FROM_GC. I
think this also guarantees that the changes made by the gc are visible
in other threads on non x86 platforms (on x86 it's already the case).

With these changes threads.impure.lisp runs 10% a faster in real time.
15 files changed:
NEWS
src/compiler/generic/objdef.lisp
src/runtime/bsd-os.c
src/runtime/bsd-os.h
src/runtime/darwin-os.h
src/runtime/interrupt.c
src/runtime/interrupt.h
src/runtime/linux-os.c
src/runtime/linux-os.h
src/runtime/sunos-os.c
src/runtime/sunos-os.h
src/runtime/thread.c
src/runtime/thread.h
src/runtime/win32-os.h
version.lisp-expr