Solaris Threads

[Back]

#define _REENTRANT_ 

#include <stdio.h>
#include <stdlib.h>
#include <thread.h>

      /* compile with command line: cc myfile.c -lthread */

typedef struct {int x, y, z; } POINT;

void * DisplayPoint(void * datum)
{
            POINT *P = (POINT *) datum;
            printf("\n Point=(%4d,%4d)\n", P->x, P->y, P->z);
            thr_exit();
}

POINT MakePoint(int x, int y, int z) 
{
         POINT P;                           /* n.b.: P is not a pointer */
         P.x = x;
         P.y = y;
         P.z = z;
         return P;                           /* notice this is passed back by value.*/
}

int main(int argc, char* argv[])
{
int i;
POINT A[10];                                /* Array of Points*/

thr_setconcurrency(10);                /* set to number of CPUs */ 

for(i=0; i<10; i++)                        /* Initialize points: (1,1,1)...(9,9,9)*/
{
         A[i] = MakePoint(i, i, i);              /* value is copied into A[i]. */
        thr_create(NULL, NULL, DisplayPoint,  &A[i], THR_LWP_CREATE, NULL); 
}


while ( thr_join(0, 0, 0) == 0);               /* wait for all threads */

return 0;                                              
}