Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <stdint.h>
- #include <inttypes.h>
- #include <pthread.h>
- void *func(void *arg) {
- sleep(4);
- printf("\n %" PRIiPTR, (intptr_t)arg);
- free(arg);
- pthread_exit(NULL);
- }
- int main(){
- int i = 1;
- int rc;
- int *p;
- int t = -1;
- pthread_t tld;
- while(i) {
- p = (int*) malloc( sizeof(int));
- if(p == NULL ){
- perror("malloc failed: ");
- pthread_exit (NULL);
- }
- t=t+1;
- *p = t;
- rc = pthread_create( &tld, NULL, func, p);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement