Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- volatile int x = 0;
- void *thread1(void *threadarg)
- {
- for (int i = 0; i < 1000000000; i++) {
- x++
- printf ("Thread 1: %d\n", x); // mach das besser weg
- }
- printf ("Thread 1 Done: %d\n", x);
- pthread_exit(NULL);
- }
- void *thread2(void *threadarg)
- {
- for (int i = 0; i < 1000000000; i++) {
- x++
- printf ("Thread 2: %d\n", x); // mach das besser weg
- }
- printf ("Thread 2 Done: %d\n", x);
- pthread_exit(NULL);
- }
- int main() {
- pthread_t threads[2]; // aus dem internet geklaut, brauche ich das?
- long t;
- pthread_create(&threads[0], NULL, thread1, (void *)t);
- pthread_create(&threads[1], NULL, thread2, (void *)t);
- void *status;
- pthread_join(thread[0], &status);
- pthread_join(thread[1], &status);
- printf ("Both threads done");
- pthread_exit(NULL);
- }
Add Comment
Please, Sign In to add comment