summaryrefslogtreecommitdiff
path: root/win32_threads.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-05-17 10:59:42 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:59 +0200
commit77ffb1ff58523f4ee461e1d1ae1a1ae1ddd9b601 (patch)
treecd94370e23c830020d44e5802f4bc3b0ec74cfd1 /win32_threads.c
parentd6f2674f15e848495b2ed9db1689e425cd2e1115 (diff)
2011-05-17 Ivan Maidanski <ivmai@mail.ru>
* pthread_support.c (pthread_join): Add assertion (check thread is finished). * pthread_support.c (GC_register_my_thread): Don't detach the thread if invoked from the thread destructor. * win32_threads.c (GC_register_my_thread): Ditto. * win32_threads.c (GC_unregister_my_thread): Don't delete the thread (just set FINISHED) if the thread is not detached (only if GC_PTHREADS); add assertion (check the thread is not finished). * tests/threadkey_test.c (main): Join some created threads.
Diffstat (limited to 'win32_threads.c')
-rw-r--r--win32_threads.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/win32_threads.c b/win32_threads.c
index cd8e8e8..68752fa 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -733,7 +733,7 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
# ifdef GC_PTHREADS
/* else */ if ((me -> flags & FINISHED) != 0) {
GC_record_stack_base(me, sb);
- me -> flags = (me -> flags & ~FINISHED) | DETACHED;
+ me -> flags &= ~FINISHED; /* but not DETACHED */
# ifdef THREAD_LOCAL_ALLOC
GC_init_thread_local((GC_tlfs)(&me->tlfs));
# endif
@@ -761,19 +761,34 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
/* Can't happen: see GC_use_threads_discovery(). */
GC_ASSERT(FALSE);
# else
+# ifdef GC_PTHREADS
+ /* FIXME: If not DETACHED then just set FINISHED. */
+# endif
/* FIXME: Should we just ignore this? */
GC_delete_thread(GetCurrentThreadId());
# endif
} else {
+# if defined(THREAD_LOCAL_ALLOC) || defined(GC_PTHREADS)
+ GC_thread me;
+# endif
DWORD thread_id = GetCurrentThreadId();
+
LOCK();
+# if defined(THREAD_LOCAL_ALLOC) || defined(GC_PTHREADS)
+ me = GC_lookup_thread_inner(thread_id);
+ GC_ASSERT(!(me -> flags & FINISHED));
+# endif
# if defined(THREAD_LOCAL_ALLOC)
- {
- GC_thread me = GC_lookup_thread_inner(thread_id);
- GC_destroy_thread_local(&(me->tlfs));
- }
+ GC_destroy_thread_local(&(me->tlfs));
+# endif
+# ifdef GC_PTHREADS
+ if ((me -> flags & DETACHED) == 0) {
+ me -> flags |= FINISHED;
+ } else
# endif
- GC_delete_thread(thread_id);
+ /* else */ {
+ GC_delete_thread(thread_id);
+ }
UNLOCK();
}
return GC_SUCCESS;