Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napisz program, w którym stworzysz jeden wątek łączny i jeden wątek rozdzielny oraz zademon-
- strujesz różnicę w działaniu tych wątków.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- void *first_thread_function(void *p)
- {
- printf("Watek laczny nr: %lu\n", pthread_self());
- return EXIT_SUCCESS;
- }
- void *second_thread_function(void *p)
- {
- printf("Watek rozdzielny nr: %lu\n", pthread_self());
- return EXIT_SUCCESS;
- }
- int main(void)
- {
- pthread_t first_thread, second_thread;
- pthread_attr_t first_attr, second_attr;
- pthread_attr_init(&first_attr);
- pthread_attr_init(&second_attr);
- pthread_attr_setdetachstate(&first_attr, PTHREAD_CREATE_JOINABLE);
- pthread_attr_setdetachstate(&second_attr, PTHREAD_CREATE_DETACHED);
- pthread_create(&first_thread, &first_attr, first_thread_function, (void *)0);
- pthread_create(&second_thread, &second_attr, second_thread_function, (void *)0);
- pthread_join(first_thread, NULL);
- pthread_join(second_thread, NULL);
- pthread_attr_destroy(&first_attr);
- pthread_attr_destroy(&second_attr);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment