This should get you started, it is a few blocks of code pulled from an OS idea I had a few years ago.
#include <iostream.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include "myrandom.h"
#define MAX 90000
// Shared data between threads
int myarr[MAX];
#ifdef USE_LOCK
pthread_mutex_t global_lock;
#endif
void *ProcessGroup1 ( void *arg );
int main ( int argc, char *argv[] )
{
*** populate array code ***
// Start the threads
void *res1, *res2, *res3;
pthread_t thr1, thr2, thr3;
double arg1, arg2, arg3;
arg1 = 1; arg2 = 2; arg3 = 3;
#ifdef USE_LOCK
pthread_mutex_init( &global_lock, NULL );
#endif
pthread_create( &thr1, NULL, ProcessGroup1, &arg1 );
pthread_create( &thr2, NULL, ProcessGroup2, &arg2 );
pthread_create( &thr3, NULL, ProcessGroup3, &arg3 );
pthread_join( thr1, &res1 );
pthread_join( thr2, &res2 );
pthread_join( thr3, &res3 );
#ifdef USE_LOCK
pthread_mutex_destroy( &global_lock );
#endif
*** Output code ***
}
// Processing Group 1 of 3
void *ProcessGroup1 ( void *arg )
{
#ifdef USE_LOCK
pthread_mutex_lock( & global_lock );
#endif
sumGroup1 = PartialSum(0, FIRST_THIRD-1, myarr);
avgGroup1 = sumGroup1 / MAGIC_NUM;
#ifdef USE_LOCK
pthread_mutex_unlock( & global_lock );
#endif
return 0;
}
*** Other Processing functions ***
*** Opeational functions ***