View difference between Paste ID: DyXD1yeF and hCAN2UJy
SHOW: | | - or go back to the newest paste.
1
#include <sys/types.h>
2
#include <sys/stat.h>
3
#include <fcntl.h>
4
#include <pthread.h>
5
#include <string.h>
6
#include <sys/file.h>
7
#include <stdlib.h>
8
#include <stdio.h>
9
#include <signal.h> 
10
#include <unistd.h>
11
#include <time.h>
12
13
14-
void *fun_watek2(void * p);
14+
15
16
char* message;
17
18-
pthread_attr_t attr;
18+
19
int main() {	
20
21
	pthread_t watek1;
22
	
23-
	pthread_t watek2;
23+
	pthread_create(&watek1, NULL, fun_watek1, (void *)&message);
24
	sleep(2);
25-
	pthread_attr_init(&attr);
25+
	pthread_kill(watek1, SIGHUP);
26
27-
	pthread_create(&watek1, &attr, fun_watek1, (void *)&message);
27+
28
29-
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
29+
30-
	pthread_create(&watek2, &attr, fun_watek2, (void *)&message);
30+
31
32
void *fun_watek1(void * p) {
33-
//tu	
33+
	int koniec = 0;
34-
	pthread_join(watek2, NULL);	
34+
35
	void syghup(int a)
36-
	pthread_attr_destroy(&attr);
36+
	{
37
		printf("Otrzymalem sygnal. Koniec\n");
38
		koniec=1;
39
	}
40
	
41-
	printf("Watek 1: %lu, PID: %d\n", pthread_self(), getpid());
41+
		signal(SIGHUP, &syghup);	
42
		printf("Watek 1: %lu, PID: %d\n", pthread_self(), getpid());		
43
		
44
		for(;;){
45
			if(koniec==1) break;
46-
void *fun_watek2(void * p) {
46+
		};	
47-
	printf("Watek 2: %lu, PID: %d\n", pthread_self(), getpid());
47+
48
	return 0;
49
}