Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <pthread.h>
- #include <stdlib.h>
- void *erhoehenumeins(void *dummy)
- {
- printf("Thread erhoehenumeins() wurde gestartet\n");
- int *temp = (int *) dummy;
- *temp++;
- printf("Thread erhoehenumeins() wurde beendet\n");
- printf("Ergebnis=%d\n",temp);
- }
- void *verdoppeln(void * dummy)
- {
- printf("Thread verdoppeln() wurde gestartet\n");
- int *temp = (int *) dummy;
- *temp *= 2;
- printf("Thread verdoppeln() wurde beendet\n");
- printf("Ergebnis=%d\n",temp);
- }
- int main() {
- int ergebnis=3;
- pthread_t thread1, thread2;
- // Thread 1 erzeugen
- pthread_create( &thread1, NULL, &erhoehenumeins, &ergebnis );
- // Thread 2 erzeugen
- pthread_create( &thread2, NULL, &verdoppeln, &ergebnis );
- // Main-Thread wartet auf beide Threads.
- pthread_join( thread1, NULL );
- pthread_join( thread2, NULL );
- printf("\nHaupt-Thread main() wurde beendet\n");
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement