Due 9/14/2011 3:59PM
The agent places two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, and the cycle repeats.
Assume the agent calls the procedure
void chooseIngredients(int *paper, int *tobacco, int *match);to randomly select 2 of the 3 ingredients. The routine randomly sets 2 of the values to "1" and one of the values to "0". You don't have to write this routine.
Write a program to synchronize the agent and smokers.
Variable Name Variable Type Initial Value Description
void parallelDo(int n, void *(function(void *)), void *arg[])parallelDo spawns off N worker threads. function is a pointer to a function, and arg[] is an array of arguments to that function (e.g., worker thread i is to execute (*function)(arg[i])). parallelDo returns once all worker threads have finished running the function.
Assume you are given mutex locks and condition variables with standard public interfaces.
Assume that you are given functions creating and destroying threads that are similar to those discussed in class:
void sthread_create(sthread_t *thrd,
void sthread_exit(void);
Implement this parallelDo function. Follow the coding standards specified in the handout. Important: follow an object-oriented style of programming - encapsulate all shared states in an object that manages access to it.