library/src/threads/BP-LinuxThreads.cc
// redispatches a thread given a thread structure
redispatches a thread given a thread structure
redispatches a thread given a thread structure
BP_ERROR_T RedispatchThread(P_THREAD_LIST thread_redispatch)
{
	if(thread_redispatch == NULL)
	{
		return ERR_FAILURE;
	}
	if(thread_redispatch->threadState != BP_THREAD_STATUS_EXITED)
		return ERR_FAILURE;
	if(thread_redispatch->threadId)
	switch(pthread_join(thread_redispatch->threadId, NULL))
	{
		case EINVAL:
			printf("\n pthread_join: EINVAL");
			break;
		case ESRCH:
			printf("\n pthread_join: ESRCH");
			break;
		case EDEADLK:
			printf("\n pthread_join: EDEADLK");
			break;
		default:
			break;
	}
	switch
	(
		pthread_create
		(
				&thread_redispatch->threadId,
				NULL,
				thread_redispatch->startRoutine,
				thread_redispatch
		)
	)
	{
		case EAGAIN:
			printf("\n pthread_create EAGAIN");
			return ERR_FAILURE;
		case EINVAL:
			printf("\n pthread_create: EINVAL");
			return ERR_FAILURE;
		case EPERM:
			printf("\n pthread_create: EPERM");
			return ERR_FAILURE;
		default:
			break;
	}
	 printf("\n [%u] thread created OK!", thread_redispatch->threadId);
	 return indicating success (thread has launched!)
	return ERR_SUCCESS;
}
BP_ERROR_T RedispatchThread ( P_THREAD_LIST thread_redispatch ) { if ( thread_redispatch == NULL ) { return ERR_FAILURE ; } if ( thread_redispatch -> threadState != BP_THREAD_STATUS_EXITED ) return ERR_FAILURE ; if ( thread_redispatch -> threadId ) switch ( pthread_join ( thread_redispatch -> threadId , NULL ) ) { case EINVAL : printf ( " \n " ) ; break ; case ESRCH : printf ( " \n " ) ; break ; case EDEADLK : printf ( " \n " ) ; break ; default : break ; } switch ( pthread_create ( & thread_redispatch -> threadId , NULL , thread_redispatch -> startRoutine , thread_redispatch ) ) { case EAGAIN : printf ( " \n " ) ; return ERR_FAILURE ; case EINVAL : printf ( " \n " ) ; return ERR_FAILURE ; case EPERM : printf ( " \n " ) ; return ERR_FAILURE ; default : break ; } return ERR_SUCCESS ; }
redispatches a thread given a thread structure
redispatches a thread given a thread structure
// ensure we have a thread structure // you can only redispatch exited threads // join the thread to bpfree resources // printf("\n thread %u joined OK!", thread_redispatch->threadId); // pthread_detach(thread_redispatch->threadId); // create thread // // printf("\n [%u] thread created OK!", thread_redispatch->threadId); // return indicating success (thread has launched!)