Advertisement
leonard007

Untitled

Jan 22nd, 2023
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <stdio.h>
  3.  
  4. void* print_digit(void* digit) {
  5.     int d = (int) digit;
  6.     printf("%d ", d);
  7.     return NULL;
  8. }
  9.  
  10. int main() {
  11.     pthread_t threads[10];
  12.  
  13.     for (int i = 0; i < 10; i++) {
  14.         pthread_create(&threads[i], NULL, print_digit, (void*) i);
  15.     }
  16.  
  17.     for (int i = 0; i < 10; i++) {
  18.         pthread_join(threads[i], NULL);
  19.     }
  20.  
  21.     printf("\n");
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement