Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef _WIN32
- #include <windows.h>
- #else
- #include <pthread.h>
- #endif
- #include <stdio.h>
- #ifdef _WIN32
- DWORD WINAPI thread_func(LPVOID lpParam)
- #else
- void *thread_func(void *arg)
- #endif
- {
- printf("En el hilo\n");
- #ifdef _WIN32
- return 0;
- #else
- return NULL;
- #endif
- }
- int main(void)
- {
- #ifdef _WIN32
- HANDLE thread = CreateThread(NULL, 0, thread_func, NULL, 0, NULL);
- if (thread == NULL) {
- printf("Error al crear el hilo\n");
- return -1;
- }
- printf("En el main\n");
- WaitForSingleObject(thread, INFINITE);
- #else
- pthread_t thread;
- int rc = pthread_create(&thread, NULL, thread_func, NULL);
- if (rc) {
- printf("Error al crear el hilo\n");
- return -1;
- }
- printf("En el main\n");
- pthread_join(thread, NULL);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement