Esempio n. 1
0
static int
native_thread_create(rb_thread_t *th)
{
    int err = 0;

    if (use_cached_thread(th)) {
        thread_debug("create (use cached thread): %p\n", (void *)th);
    }
    else {
        pthread_attr_t attr;
        size_t stack_size = 512 * 1024; /* 512KB */
        size_t space;

#ifdef PTHREAD_STACK_MIN
        if (stack_size < PTHREAD_STACK_MIN) {
            stack_size = PTHREAD_STACK_MIN * 2;
        }
#endif
        space = stack_size/5;
        if (space > 1024*1024) space = 1024*1024;
        th->machine_stack_maxsize = stack_size - space;
#ifdef __ia64
        th->machine_stack_maxsize /= 2;
        th->machine_register_stack_maxsize = th->machine_stack_maxsize;
#endif

        CHECK_ERR(pthread_attr_init(&attr));

#ifdef PTHREAD_STACK_MIN
        thread_debug("create - stack size: %lu\n", (unsigned long)stack_size);
        CHECK_ERR(pthread_attr_setstacksize(&attr, stack_size));
#endif

#ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED
        CHECK_ERR(pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED));
#endif
        CHECK_ERR(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED));

        err = pthread_create(&th->thread_id, &attr, thread_start_func_1, th);
        thread_debug("create: %p (%d)", (void *)th, err);
        CHECK_ERR(pthread_attr_destroy(&attr));

        if (!err) {
            pthread_cond_init(&th->native_thread_data.sleep_cond, 0);
        }
        else {
            st_delete_wrap(th->vm->living_threads, th->self);
            th->status = THREAD_KILLED;
            rb_raise(rb_eThreadError, "can't create Thread (%d)", err);
        }
    }
    return err;
}
Esempio n. 2
0
static int
native_thread_create(rb_thread_t *th)
{
    size_t stack_size = 4 * 1024; /* 4KB */
    th->thread_id = w32_create_thread(stack_size, thread_start_func_1, th);

    if ((th->thread_id) == 0) {
	st_delete_wrap(th->vm->living_threads, th->self);
	rb_raise(rb_eThreadError, "can't create Thread (%d)", errno);
    }

    w32_resume_thread(th->thread_id);

    if (THREAD_DEBUG) {
	Sleep(0);
	thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %d\n",
		     th, th->thread_id,
		     th->native_thread_data.interrupt_event, stack_size);
    }
    return 0;
}