GRealThread thread;
pthread_t system_thread;
+ gboolean joined;
+ GMutex lock;
} GThreadPosix;
void
{
GThreadPosix *pt = (GThreadPosix *) thread;
+ if (!pt->joined)
+ pthread_detach (pt->system_thread);
+
+ g_mutex_clear (&pt->lock);
+
g_slice_free (GThreadPosix, pt);
}
}
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
- posix_check_cmd (pthread_attr_setdetachstate (&attr,
- joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
-
ret = pthread_create (&thread->system_thread, &attr, (void* (*)(void*))thread_func, thread);
posix_check_cmd (pthread_attr_destroy (&attr));
posix_check_err (ret, "pthread_create");
+ g_mutex_init (&thread->lock);
+
return (GRealThread *) thread;
}
g_system_thread_wait (GRealThread *thread)
{
GThreadPosix *pt = (GThreadPosix *) thread;
- gpointer ignore;
- posix_check_cmd (pthread_join (pt->system_thread, &ignore));
+
+ g_mutex_lock (&pt->lock);
+
+ if (!pt->joined)
+ {
+ posix_check_cmd (pthread_join (pt->system_thread, NULL));
+ pt->joined = TRUE;
+ }
+
+ g_mutex_unlock (&pt->lock);
}
void