library/src/threads/BP-LinuxThreads.cc
// creates a thread and returns it in a list structure
// arg is the data pointer being passed to the thread, argLen is
// recorded locally in the P_THREAD_LIST returned to be
// referencable.
//
//
// IMPORTANT IMPORTANT READ THIS STUPID, THAT MEANS YOU JASON
//
// The destination "void * function(void *arg)" has an passed argument type of P_THREAD_LIST not
// the argument type that you submitted.  You have to cast the argument (upon reciveing it
// in the void function) to P_THREAD_LIST or your code will be all fudged up.
//
creates a thread and returns it in a list structure
arg is the data pointer being passed to the thread, argLen is
recorded locally in the P_THREAD_LIST returned to be
referencable.

IMPORTANT IMPORTANT READ THIS STUPID, THAT MEANS YOU JASON

The destination "void * function(void *arg)" has an passed argument type of P_THREAD_LIST not
the argument type that you submitted.  You have to cast the argument (upon reciveing it
in the void function) to P_THREAD_LIST or your code will be all fudged up.
creates a thread and returns it in a list structure arg is the data pointer being passed to the thread argLen is recorded locally in the P_THREAD_LIST returned to be referencable . IMPORTANT IMPORTANT READ THIS STUPID THAT MEANS YOU JASON The destination " void * function ( void * arg ) " has an passed argument type of P_THREAD_LIST not the argument type that you submitted . You have to cast the argument ( upon reciveing it in the void function ) to P_THREAD_LIST or your code will be all fudged up .
P_THREAD_LIST CreateThread(void *(startRoutine)(void*), void *arg, int argLen, char * description, P_BP_THREAD_MGMT thread_mgmt_data)
{
	if(startRoutine == NULL)
	{
		return NULL;
	}
	P_THREAD_LIST threadList = (P_THREAD_LIST) bpcalloc(sizeof(THREAD_LIST), 1);
	threadList->first = threadList;
	threadList->prev = NULL;
	threadList->next = NULL;
	threadList->startRoutine = startRoutine;
	threadList->sharedData     = arg;
	threadList->sharedDataSize = argLen;
	threadList->thread_lock = PTHREAD_MUTEX_INITIALIZER;
	threadList->thread_mgmt_data = thread_mgmt_data;
	threadList->threadId = 0;
	if(description != NULL)
	{
		threadList->threadDescription = (char *) bpcalloc(strnlen(description, 1024)+10, 1);
		memcpy(threadList->threadDescription, description, strnlen(description, 1024));
	}
	if(pthread_create(&threadList->threadId, NULL, startRoutine, threadList) != 0)
	{
		if(threadList->threadDescription != NULL)
			bpfree(threadList->threadDescription);
		bpfree(threadList);
		return NULL;
	}
	return threadList;
}
P_THREAD_LIST CreateThread ( void * ( startRoutine ) ( void * ) , void * arg , int argLen , char * description , P_BP_THREAD_MGMT thread_mgmt_data ) { if ( startRoutine == NULL ) { return NULL ; } P_THREAD_LIST threadList = ( P_THREAD_LIST ) bpcalloc ( sizeof ( THREAD_LIST ) , 1 ) ; threadList -> first = threadList ; threadList -> prev = NULL ; threadList -> next = NULL ; threadList -> startRoutine = startRoutine ; threadList -> sharedData = arg ; threadList -> sharedDataSize = argLen ; threadList -> thread_lock = PTHREAD_MUTEX_INITIALIZER ; threadList -> thread_mgmt_data = thread_mgmt_data ; threadList -> threadId = 0 ; if ( description != NULL ) { threadList -> threadDescription = ( char * ) bpcalloc ( strnlen ( description , 1024 ) + 10 , 1 ) ; memcpy ( threadList -> threadDescription , description , strnlen ( description , 1024 ) ) ; } if ( pthread_create ( & threadList -> threadId , NULL , startRoutine , threadList ) != 0 ) { if ( threadList -> threadDescription != NULL ) bpfree ( threadList -> threadDescription ) ; bpfree ( threadList ) ; return NULL ; } return threadList ; }
creates a thread and returns it in a list structure
arg is the data pointer being passed to the thread, argLen is
recorded locally in the P_THREAD_LIST returned to be
referencable.
creates a thread and returns it in a list structure arg is the data pointer being passed to the thread argLen is recorded locally in the P_THREAD_LIST returned to be referencable .
// ensure we have a start routine // create a new thread list element // set list pointers // save start routine pointer for identification // save pointer to thread argument data along with size // initialize thread lock // set thread managment data // initialize set thread id // copy in description string // allocate space for the description // copy in the description // create thread (pass thread list as a pointer) // bpfree bpmalloc'ed member pointers (cleanup) // bpfree whole structure (cleanup) // exit routine // Return with the newly populated thread list.  Lock the mutex inside // this thread list element before trying to access members within as // it may cause a race condition otherwise.