What I meant with the message system was something like this:
Code:
Process_A ()
{
while (1)
{
wake_up = false;
while (wake_up == false)
{
/* Check message buffer */
switch (message)
{
case WAKE_PROCESS_A:
/* Wake up process A only */
wake_up = true;
break;
case WAKE_ALL_PROCESSS:
/* Wake up all processes */
wake_up = true;
case ....
/* Some other messages on which
the process should wake up */
default:
break;
}
}
/* Now the process has waken up and must do
the things it needs to do. */
...
/* Everything that need to be done is done,
the process can sleep again. */
wake_up = false;
}
}
There are some other methods, but I see that your method works. It looks OK, although personally I would split control and data. So I would have some global array in which the condition variables are stored. The threads only check their condition variable and wake up if necessary.