library/src/threads/BP-LinuxThreads.cc
// Attempts to find an exited thread, and redispatch it.
Attempts to find an exited thread, and redispatch it.
Attempts to find an exited thread and redispatch it .
BP_ERROR_T BP_RedispatchThread
(
	P_BP_THREAD_MANAGER thread_manager,
	void *   arg,
	size_t   arg_len,
	size_t   arg_idx
)
{
	if(!thread_manager)
		return ERR_FAILURE;
	P_BP_MANAGED_THREAD managed_thread = NULL;
	do
	{
		BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION;
		managed_thread = BP_FindThreadDispatchCandidate(thread_manager);
		BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION;
		usleep(100);
	}
	while(!managed_thread);
	BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION;
	if
	(
			managed_thread->current_status == BP_THREAD_STATUS_LOCKED_FOR_REDISPATCH ||
			managed_thread->current_status == BP_THREAD_STATUS_EXITED
	)
	{
		BP_RejoinThread(thread_manager, managed_thread, BP_TRUE, BP_TRUE);
	}
	BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION
	BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION;
	managed_thread->thread_parameter      = arg;
	managed_thread->thread_parameter_size = arg_len;
	managed_thread->thread_parameter_idx  = arg_idx;
	BP_StartThread(thread_manager, managed_thread);
	BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_RedispatchThread ( P_BP_THREAD_MANAGER thread_manager , void * arg , size_t arg_len , size_t arg_idx ) { if ( ! thread_manager ) return ERR_FAILURE ; P_BP_MANAGED_THREAD managed_thread = NULL ; do { BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION ; managed_thread = BP_FindThreadDispatchCandidate ( thread_manager ) ; BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION ; usleep ( 100 ) ; } while ( ! managed_thread ) ; BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION ; if ( managed_thread -> current_status == BP_THREAD_STATUS_LOCKED_FOR_REDISPATCH || managed_thread -> current_status == BP_THREAD_STATUS_EXITED ) { BP_RejoinThread ( thread_manager , managed_thread , BP_TRUE , BP_TRUE ) ; } BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION ; managed_thread -> thread_parameter = arg ; managed_thread -> thread_parameter_size = arg_len ; managed_thread -> thread_parameter_idx = arg_idx ; BP_StartThread ( thread_manager , managed_thread ) ; BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION ; return ERR_SUCCESS ; }
Attempts to find an exited thread, and redispatch it.
Attempts to find an exited thread and redispatch it .
// ensure we have a thread manager // managed thread to lookup // attempt to find a thread dispatch candidate // if(managed_thread) // printf("\n Managed Thread: %p", managed_thread); // sleep for a bit so we don't just spin like crazy // enter critical section // check status and attempt to rejoin the thread // try to rejoin the candidate before dispatching.  Lock the manager, but // don't lock the individual thread (as it's already locked via this function) // leave critical section // enter critical section // set thread parameter and parameter size // attempt to start the thread // leave critical section // return indicating success