Created
May 8, 2013 14:49
-
-
Save stevenleeg/5540959 to your computer and use it in GitHub Desktop.
Playing with threads
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 <pthread.h> | |
#include <stdio.h> | |
void count() { | |
int i = 0; | |
for(i = 0; i < 10; i++) { | |
usleep(1); | |
printf("Counting: %d\n", i); | |
} | |
} | |
int main(void) { | |
printf("Hello world\n"); | |
pthread_t pth1; | |
pthread_create(&pth1, NULL, count, NULL); | |
pthread_t pth2; | |
pthread_create(&pth2, NULL, count, NULL); | |
pthread_join(pth1, NULL); | |
pthread_join(pth2, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment