+#ifdef LISP_FEATURE_SB_THREAD
+os_thread_t create_thread(lispobj initial_function) {
+ struct thread *th;
+ os_thread_t kid_tid=0;
+ pthread_attr_t attr;
+
+ if(linux_no_threads_p) return 0;
+ th=create_thread_struct(initial_function);
+ if(th==0) return 0;
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:waiting on lock");
+#endif
+ get_spinlock(&thread_start_lock,arch_os_get_current_thread()->os_thread);
+#ifdef QSHOW_SIGNALS
+ SHOW("create_thread:got lock");
+#endif
+ /* 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;
+ }
+}
+#endif