# ifdef GC_PTHREADS
int err;
pthread_t th;
+
err = pthread_create(&th, NULL, entry, (void *)my_depth);
- if (err) {
+ if (err != 0) {
fprintf(stderr, "Thread #%d creation failed: %s\n", thread_num,
strerror(err));
exit(2);
}
+ err = pthread_detach(th);
+ if (err != 0) {
+ fprintf(stderr, "Thread #%d detach failed: %s\n", thread_num,
+ strerror(err));
+ exit(2);
+ }
# else
HANDLE th;
DWORD thread_id;
+
th = CreateThread(NULL, 0, entry, (LPVOID)my_depth, 0, &thread_id);
if (th == NULL) {
fprintf(stderr, "Thread #%d creation failed: %d\n", thread_num,
pthread_t t;
int creation_res; /* Used to suppress a warning about */
/* unchecked pthread_create() result. */
+ pthread_attr_t attr;
- creation_res = GC_pthread_create (&t, NULL, entry, NULL);
+ if (pthread_attr_init(&attr) != 0
+ || pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) {
+ fprintf(stderr, "Thread attribute init or setdetachstate failed\n");
+ exit(2);
+ }
+ creation_res = GC_pthread_create(&t, &attr, entry, NULL);
+ (void)pthread_attr_destroy(&attr);
if (res == GC_SUCCESS)
GC_unregister_my_thread ();
# endif
for (i = 0; i < LIMIT; i++) {
pthread_t t;
- void *res;
- if (GC_pthread_create (&t, NULL, entry, NULL) == 0
- && (i & 1) != 0) {
- int code = GC_pthread_join(t, &res);
+
+ 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 join failed %d\n", code);
+ fprintf(stderr, "Thread %s failed %d\n",
+ (i & 1) != 0 ? "join" : "detach", code);
exit(2);
}
}