Created
August 7, 2017 16:15
-
-
Save hamadu/f1b090ce84108494a1176b2a350a859d to your computer and use it in GitHub Desktop.
thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdio.h> | |
#include <pthread.h> | |
int global_num = 100; | |
void* another(void *arg) { | |
global_num = 200; | |
printf("hello from another thread: %d\n", global_num); | |
global_num = 300; | |
} | |
int main(int argc, char* argv[]) { | |
pthread_t thread; | |
pthread_create(&thread, NULL, *another, NULL); | |
sleep(3); | |
printf("hello from main thread: %d\n", global_num); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment