Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- volatile int licznik;
- void *print_message_function( void *ptr )
- {
- char *message;
- message = (char *) ptr;
- printf("%s \n", message);
- }
- void *elo();
- void *elo1()
- {
- while(1)
- {
- licznik++;
- }
- }
- int main()
- {
- pthread_t thread1, thread2;
- const char *message1 = "Thread 1";
- const char *message2 = "Thread 2";
- int iret1, iret2;
- /* Create independent threads each of which will execute function */
- iret1 = pthread_create( &thread1, NULL, elo, (void*) message1);
- iret2 = pthread_create( &thread2, NULL, elo1, (void*) message2);
- pthread_join( thread1, NULL);
- pthread_join( thread2, NULL);
- exit(EXIT_SUCCESS);
- }
- void *elo()
- {
- while(1)
- {
- printf("Elo %d \n", licznik);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment