Changeset: 39737ad1c6b9 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=39737ad1c6b9 Modified Files: gdk/gdk_system.c Branch: Jun2016 Log Message:
Cleanup, plus implement join_detached_threads for Windows. diffs (92 lines): diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -233,11 +233,32 @@ join_threads(void) } while (waited); } +void +join_detached_threads(void) +{ + struct winthread *w; + + EnterCriticalSection(&winthread_cs); + while (winthreads) { + w = winthreads; + winthreads = w->next; + LeaveCriticalSection(&winthread_cs); + WaitForSingleObject(w->hdl, INFINITE); + CloseHandle(w->hdl); + free(w); + EnterCriticalSection(&winthread_cs); + } + LeaveCriticalSection(&winthread_cs); +} + int MT_create_thread(MT_Id *t, void (*f) (void *), void *arg, enum MT_thr_detach d) { struct winthread *w = malloc(sizeof(*w)); + if (w == NULL) + return -1; + if (winthread_cs_init == 0) { /* we only get here before any threads are created, * and this is the only time that winthread_cs_init is @@ -501,23 +522,18 @@ void join_detached_threads(void) { struct posthread *p; - int waited; pthread_t tid; pthread_mutex_lock(&posthread_lock); - do { - waited = 0; - for (p = posthreads; p; p = p->next) { - tid = p->tid; - rm_posthread_locked(p); - free(p); - pthread_mutex_unlock(&posthread_lock); - pthread_join(tid, NULL); - pthread_mutex_lock(&posthread_lock); - waited = 1; - break; - } - } while (waited); + while (posthreads) { + p = posthreads; + posthreads = p->next; + tid = p->tid; + free(p); + pthread_mutex_unlock(&posthread_lock); + pthread_join(tid, NULL); + pthread_mutex_lock(&posthread_lock); + } pthread_mutex_unlock(&posthread_lock); } @@ -542,6 +558,12 @@ MT_create_thread(MT_Id *t, void (*f) (vo pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (d == MT_THR_DETACHED) { p = malloc(sizeof(struct posthread)); + if (p == NULL) { +#ifdef HAVE_PTHREAD_SIGMASK + MT_thread_sigmask(&orig_mask, NULL); +#endif + return -1; + } p->func = f; p->arg = arg; p->exited = 0; @@ -789,6 +811,9 @@ MT_check_nr_cores_(void) lng t0, t1; MT_Id *threads = malloc(sizeof(MT_Id) * curr); + if (threads == NULL) + break; + t0 = GDKusec(); for (i = 0; i < curr; i++) MT_create_thread(threads + i, smp_thread, NULL, MT_THR_JOINABLE); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list