Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <pthread.h>
- void* function1(void* _signal) {
- int signal = *(int*)_signal;
- sigset_t set;
- siginfo_t info;
- sigfillset(&set);
- sigdelset(&set, SIGRTMIN);
- pthread_sigmask(SIG_SETMASK, &set, NULL);
- sigemptyset(&set);
- sigaddset(&set, SIGRTMIN);
- while (1) {
- sigwaitinfo(&set, &info);
- printf("Received %u thread with value %d; Signal -> %d\n", (int)pthread_self(), info.si_value.sival_int, info.si_signo);
- }
- return NULL;
- }
- void* function2(void* _signal) {
- int signal = *(int*)_signal;
- sigset_t set;
- siginfo_t info;
- sigfillset(&set);
- sigdelset(&set, SIGRTMIN+1);
- pthread_sigmask(SIG_SETMASK, &set, NULL);
- sigemptyset(&set);
- sigaddset(&set, SIGRTMIN+1);
- while (1) {
- sigwaitinfo(&set, &info);
- printf("Received %u thread with value %d; Signal -> %d\n", (int)pthread_self(), info.si_value.sival_int, info.si_signo);
- }
- return NULL;
- }
- int main() {
- pthread_t tid1, tid2;
- sigset_t set;
- // Blokujemy sygnaly 41 oraz 42
- sigemptyset(&set);
- sigaddset(&set, SIGRTMIN);
- sigaddset(&set, SIGRTMIN+1);
- pthread_sigmask(SIG_BLOCK, &set, NULL);
- pthread_create(&tid1, NULL, function1, NULL);
- pthread_create(&tid2, NULL, function2, NULL);
- pthread_join(tid1, NULL);
- pthread_join(tid2, NULL);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement