Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- long counter = 0;
- void* printCounter() {
- while (1) {
- printf("%ld\n", counter);
- }
- }
- void* incrementCounter() {
- while (1) {
- counter++;
- }
- }
- int main() {
- pthread_t printer, incrementer;
- pthread_create(&printer, NULL, printCounter, NULL);
- pthread_create(&incrementer, NULL, incrementCounter, NULL);
- pthread_join(incrementer, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment