Beispiel #1
0
int
pthread_create(pthread_t* _thread, const pthread_attr_t* attr,
	void* (*startRoutine)(void*), void* arg)
{
	if (_thread == NULL)
		return EINVAL;

	pthread_thread* thread = __allocate_pthread(startRoutine, arg);
	if (thread == NULL)
		return EAGAIN;

	thread_creation_attributes attributes;
	status_t error = __pthread_init_creation_attributes(attr, thread,
		&pthread_thread_entry, NULL, thread, "pthread func", &attributes);
	if (error != B_OK) {
		free(thread);
		return error;
	}

	thread->id = _kern_spawn_thread(&attributes);
	if (thread->id < 0) {
		// stupid error code but demanded by POSIX
		free(thread);
		return EAGAIN;
	}

	__set_stack_protection();
	*_thread = thread;
	resume_thread(thread->id);

	return 0;
}
Beispiel #2
0
thread_id
spawn_thread(thread_func entry, const char *name, int32 priority, void *data)
{
	struct thread_creation_attributes attributes;
	pthread_thread* thread;
	thread_id id;

	thread = __allocate_pthread(NULL, data);
	if (thread == NULL)
		return B_NO_MEMORY;

	_single_threaded = false;
		// used for I/O locking - BeOS compatibility issue

	__pthread_init_creation_attributes(NULL, thread, &thread_entry, entry,
		thread, name, &attributes);

	attributes.priority = priority;

	id = _kern_spawn_thread(&attributes);
	if (id < 0)
		free(thread);
	else {
		thread->id = id;
		__set_stack_protection();
	}

	return id;
}