#include "mp.h" #include typedef struct { void *(*func)(void *); void *arg; entity_t e_id; } mp_wrapper_t; /* NOTE that you must modify this function -- this is only a template! */ void* mp_wrap(void* mwt) { mp_wrapper_t* mw = (mp_wrapper_t*)mwt; entity_t my_id = mw->e_id; void *arg = mw->arg; void *result; /* TODO: set up thread-specific data (use pthread functions) for entity ID or mailbox here */ result = mw->func(arg); free(arg); /* signal that we're done */ mp_send(MAIN_ENTITY, TAG_DONE, 0, NULL); pthread_exit(result); } int mp_new_thread(entity_t entity_id, void * (*func)(void *), void * arg) { mp_wrapper_t* mw; pthread_t pth; mw = malloc(sizeof(mp_wrapper_t)); mw->func = func; mw->arg = arg; mw->e_id = entity_id; return pthread_create(&pth, NULL, mp_wrap, mw); }