Advertisement
unstoppable7

Untitled

Feb 5th, 2023
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #ifdef _WIN32
  2. #include <windows.h>
  3. #else
  4. #include <pthread.h>
  5. #endif
  6. #include <stdio.h>
  7.  
  8. #ifdef _WIN32
  9. DWORD WINAPI thread_func(LPVOID lpParam)
  10. #else
  11. void *thread_func(void *arg)
  12. #endif
  13. {
  14.     printf("En el hilo\n");
  15. #ifdef _WIN32
  16.     return 0;
  17. #else
  18.     return NULL;
  19. #endif
  20. }
  21.  
  22. int main(void)
  23. {
  24. #ifdef _WIN32
  25.     HANDLE thread = CreateThread(NULL, 0, thread_func, NULL, 0, NULL);
  26.     if (thread == NULL) {
  27.         printf("Error al crear el hilo\n");
  28.         return -1;
  29.     }
  30.     printf("En el main\n");
  31.     WaitForSingleObject(thread, INFINITE);
  32. #else
  33.     pthread_t thread;
  34.     int rc = pthread_create(&thread, NULL, thread_func, NULL);
  35.     if (rc) {
  36.         printf("Error al crear el hilo\n");
  37.         return -1;
  38.     }
  39.  
  40.     printf("En el main\n");
  41.     pthread_join(thread, NULL);
  42. #endif
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement