Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- /* This is our thread function. It is like main(), but for a thread*/
- void *threadFunc(void *arg)
- {
- int *str;
- int i = 0;
- str=(char*)arg;
- while(i < 110 )
- {
- usleep(1);
- printf("threadFunc says: %s\n",str);
- ++i;
- }
- return NULL;
- }
- int main(void)
- {
- pthread_t pth; // this is our thread identifier
- int i = 0;
- int a = 0;
- for(a = 0; a < 255; a++){
- pthread_create(&pth,NULL,threadFunc,a);
- }
- while(i < 100)
- {
- usleep(1);
- printf("main is running...\n");
- ++i;
- }
- printf("main waiting for thread to terminate...\n");
- pthread_join(pth,NULL);
- return 0;
- }
Add Comment
Please, Sign In to add comment