OSF DCE Application Development Guide--Core Components

DCE Threads Example
}
else if (count == request) {
not_done = 0;
count++;
for (notifiee = 0; notifiee < workers; notifiee++) {
if (notifiee != my_number) {
status = pthread_cancel ( threads[notifiee] );
check(status,"12:Cancel bad status\n");
}
}
}
status = pthread_mutex_unlock (&prime_list);
check(status,"13:Mutex_unlock bad status\n");
/* Reenable cancels */
pthread_setcancel(CANCEL_ON);
}
pthread_testcancel ();
}
pthread_exit (my_number);
}
main()
{
int worker_num; /* Counter used when indexing workers */
int exit_value; /* Individual worker’s return status */
int list; /* Used to print list of found primes */
int status; /* Hold status from pthread calls */
int index1; /* Used in sorting prime numbers */
int index2; /* Used in sorting prime numbers */
int temp; /* Used in a swap; part of sort */
int not_done; /* Indicates swap made in sort */
* Create mutexes
*/
status = pthread_mutex_init (&prime_list, pthread_mutexattr_default);
check(status,"15:Mutex_init bad status\n");
status = pthread_mutex_init (&cond_mutex, pthread_mutexattr_default);
check(status,"16:Mutex_init bad status\n");
status = pthread_mutex_init (&current_mutex, pthread_mutexattr_default);
check(status,"17:Mutex_init bad status\n");
/*
* Create conditon variable
*/
status = pthread_cond_init (&cond_var, pthread_condattr_default);
check(status,"45:Cond_init bad status\n");
/*
* Create the worker threads.
*/
for (worker_num = 0; worker_num < workers; worker_num++) {
status = pthread_create (
&threads[worker_num],
pthread_attr_default,
124245 Tandem Computers Incorporated 105