int main (void) { int i; GC_INIT (); # ifdef GC_SOLARIS_THREADS pthread_key_create (&key, on_thread_exit); # else pthread_once (&key_once, make_key); # endif for (i = 0; i < NTHREADS; i++) { pthread_t t; if (GC_pthread_create(&t, NULL, entry, NULL) == 0) { void *res; int code = (i & 1) != 0 ? GC_pthread_join(t, &res) : GC_pthread_detach(t); if (code != 0) { fprintf(stderr, "Thread %s failed %d\n", (i & 1) != 0 ? "join" : "detach", code); exit(2); } } } return 0; }
int mz_proc_thread_detach(mz_proc_thread *thread) { int rc; #ifdef WIN32 rc = CloseHandle(thread->threadid); #else # ifdef NEED_GC_THREAD_OPS rc = GC_pthread_detach(thread->threadid); # else rc = pthread_detach(thread->threadid); # endif #endif if (!--thread->refcount) free(thread); return rc; }
void create_profiler_thread(void * (* start)(void *)) { pthread_t id; long status = GC_pthread_create(&id, NULL, start, NULL); if (status != 0) { printf("GC_pthread_create status = %ld\n", status); fflush(stdout); signal_lisp_error("Unable to create profiler thread."); return; } status = GC_pthread_detach(id); if (status != 0) { printf("GC_pthread_detach status = %ld\n", status); fflush(stdout); signal_lisp_error("Unable to detach profiler thread."); return; } sched_yield(); }