Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void *thread_main(void *thread_number) {
- printf("In thread number %d.n", *(int *)thread_number);
- }
- void main() {
- int i = 0;
- pthread_t thread;
- for( i = 0; i < 10; i++ ) {
- printf("Creating thread %d.n");
- pthread_create(&thread, 0, thread_main, &i);
- printf("Created thread %d.n");
- }
- }
- > Creating thread 1.
- > In thread number 1.
- > Created thread 1.
- > Creating thread 2.
- > In thread number 2.
- > Created thread 2.
- for( i = 0; i < 10; i++ ) {
- int *thread_count = malloc(sizeof(int));
- *thread_count = i;
- printf("Creating thread %d.n", i);
- pthread_create(&thread, 0, thread_main, thread_count);
- printf("Created thread %d.n", i);
- }
- void *thread_main(void *thread_number) {
- printf("In thread number %d.n", *(int *)thread_number);
- free(thread_numbr);
- }
Add Comment
Please, Sign In to add comment