Problem writing thread program in Solaris
I writing a program creating a virtual circle with n
threads, they execute one by one, printing their id
and sending a signal to the next.
Basically, I need to create n number of threads, each receiving a
different parameter, zero to n-1, which is going
to be each thread’s id. I need to create an array of cond_t variables
using malloc (n * sizeof (cond_t)). How do I make n number of threads?
Also, am I using malloc correctly?
This is the psuedo code I have so far:
Code:
#include <stdio.h>
#include <thread.h>
#include <synch.h>
mutex_t mp;
cond_t cp;
malloc (n * sizeof (cond_t));
int main()
{
int i;
mutex_init (&mp, 0, NULL);
cond_init (&cp, 0, NULL);
thr_create(NULL, i, loop, (void *) NULL, NULL, NULL);
for(i = 0, i>n, i++)
{
}
}
void*
loop(void* arg)
{
if(id = 0)
{
printf("%s\n", id);
sleep(5);
cond_signal(&cp[i]);
mutex_lock(&mp);
cond_wait();
mutex_unlock(&imp);
}
else
{
mutex_lock(&mp);
cond_wait(&cp[i]);
mutex_unlock(&mp)
printf("%s\n", id)
sleep(5);
cond_signal(id+1)%n;
}