Home Operating System Solaris How can threads be created in a solaris environment? Write an example The function thr_create() function can be used for the creation of a thread. The syntax for the creation of a thread is: int thr_create( NULL, 0, void *(*funct)(void *), void *arg, 0, thread_t *ID); When the function thr_thread() is called it creates a child thread. This will execute concurrently with the parent thread.Code: #include #include void *count(void *JunkPTR) { int *valuePTR = (int *) JunkPTR; /* convert to integer ptr. */ int value = *valuePTR; /* then take the value */ printf("Child: value = %d\n", value); } void main(void) { thread_t ID1, ID2; int v1 = 1; int v2 = 2; thr_create(NULL, 0, count, (void *) (&v1), 0, &ID1); thr_create(NULL, 0, count, (void *) (&v2), 0, &ID2); printf("Parent\n"); sleep(2); } The above code on execution would create two threads. Both the threads would be a copy of the count() function.
Post a Comment