library/src/threads/BP-LinuxThreads.cc
// Attempt to rejoin all the threads
Attempt to rejoin all the threads
Attempt to rejoin all the threads
BP_ERROR_T BP_RejoinAllThreads(P_BP_THREAD_MANAGER thread_manager, BP_BOOL only_try_to_reclaim_dont_force)
{
	if(!thread_manager)
		return ERR_FAILURE;
	if(!thread_manager->threads || !thread_manager->threads_n)
		return ERR_FAILURE;
	if(!thread_manager->threads_running_n)
		return ERR_FAILURE;
	P_BP_MANAGED_THREAD managed_thread = NULL;
	size_t n = 0;
	do
	{
		for(n=0; n < thread_manager->threads_n; n++)
		{
			BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION;
			managed_thread = thread_manager->threads[n];
			BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION
			if(managed_thread->current_status == BP_THREAD_STATUS_REJOINED)
			{
				continue;
			}
			BP_RejoinThread(thread_manager, managed_thread, BP_TRUE, BP_FALSE);
		}
	} while(thread_manager->threads_running_n && only_try_to_reclaim_dont_force);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_RejoinAllThreads ( P_BP_THREAD_MANAGER thread_manager , BP_BOOL only_try_to_reclaim_dont_force ) { if ( ! thread_manager ) return ERR_FAILURE ; if ( ! thread_manager -> threads || ! thread_manager -> threads_n ) return ERR_FAILURE ; if ( ! thread_manager -> threads_running_n ) return ERR_FAILURE ; P_BP_MANAGED_THREAD managed_thread = NULL ; size_t n = 0 ; do { for ( n = 0 ; n < thread_manager -> threads_n ; n ++ ) { BP_THREAD_MANAGER_ENTER_CRITICAL_SECTION ; managed_thread = thread_manager -> threads [ n ] ; BP_THREAD_MANAGER_LEAVE_CRITICAL_SECTION if ( managed_thread -> current_status == BP_THREAD_STATUS_REJOINED ) { continue ; } BP_RejoinThread ( thread_manager , managed_thread , BP_TRUE , BP_FALSE ) ; } } while ( thread_manager -> threads_running_n && only_try_to_reclaim_dont_force ) ; return ERR_SUCCESS ; }
Attempt to rejoin all the threads
Attempt to rejoin all the threads
// ensure we have a thread manager // ensure we have threads to check // ensure that we have some running threads // declare pointer for managed thread // NOTE: DO NOT PUT ENTIRE LOOP IN A CRITICAL SECTION.  IT WILL //       CAUSE A DEADLOCK. // enter critical section // set managed thread // leave critical section // only try to rejoin unjoined threads // attempt to rejoin the thread (lock manager and thread during rejoin) // thread couldn't join