- get_spinlock(&all_threads_lock,th->pid);
- if(countdown_to_gc>0) countdown_to_gc--;
- if(th==all_threads)
- all_threads=th->next;
- else {
- struct thread *th1=all_threads;
- while(th1->next!=th) th1=th1->next;
- th1->next=th->next; /* unlink */
+ /* The new thread inherits the restrictive signal mask set here,
+ * and enables signals again when it is set up properly. */
+ {
+ sigset_t newset,oldset;
+ sigemptyset(&newset);
+ sigaddset_blockable(&newset);
+ thread_sigmask(SIG_BLOCK, &newset, &oldset);
+ if((pthread_attr_init(&attr)) ||
+ (pthread_attr_setstack(&attr,th->control_stack_start,
+ THREAD_CONTROL_STACK_SIZE-16)) ||
+ (pthread_create
+ (&kid_tid,&attr,(void *(*)(void *))new_thread_trampoline,th)))
+ kid_tid=0;
+ thread_sigmask(SIG_SETMASK,&oldset,0);
+ }
+ if(kid_tid>0) {
+ link_thread(th,kid_tid);
+ /* it's started and initialized, it's safe to gc */
+ release_spinlock(&thread_start_lock);
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:released lock");
+#endif
+ /* by now the kid might have already exited */
+ return kid_tid;
+ } else {
+ release_spinlock(&thread_start_lock);
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:released lock(failure)");
+#endif
+ os_invalidate((os_vm_address_t) th->control_stack_start,
+ ((sizeof (lispobj))
+ * (th->control_stack_end-th->control_stack_start)) +
+ BINDING_STACK_SIZE+ALIEN_STACK_SIZE+dynamic_values_bytes+
+ 32*SIGSTKSZ);
+ return 0;