Exemple #1
0
int Create(ucontext_t* starting_context)
{
	if(thread_counter + 1 > MAX_THREADS) // Maximum number of threads reached. We don't create the thread.
	{
		return ERROR;
	}

	TCB* thread = TCB_create(tid_counter, starting_context, READY);

	if(thread == NULL)
	{
		return ERROR;
	}

	tid_counter++;
	thread_counter++;

	int result = TCB_list_add(all_threads, thread);

	if(result == ERROR)
	{
		return ERROR;
	}

	return Ready(thread); // Changes the thread state to "ready" and enqueues it
}
Exemple #2
0
int TCB_block(TCB* waiting_thread, TCB* blocking_thread)
{
	if(blocking_thread == NULL)
	{
		return ERROR;
	}
	else if(waiting_thread == NULL)
	{
		return ERROR;
	}
	else
	{
		TCB_list_add(blocking_thread->waiting_for_me, waiting_thread);

		waiting_thread->state = BLOCKED;

		return NO_ERROR;
	}
}