summaryrefslogtreecommitdiff
path: root/lib/libc_r/TEST/test_setjmp.c
blob: dab429cc7ad1a976f0bf80ccdc1c79d0dc47d7fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*	$OpenBSD: test_setjmp.c,v 1.5 2000/01/06 06:58:34 d Exp $	*/
#include <setjmp.h>
#include "test.h"

int reached;

void *
_jump(arg)
	void *arg;
{
	jmp_buf foo;

	reached = 0;
	if (_setjmp(foo)) {
		ASSERT(reached);
		return NULL;
	}
	reached = 1;
	_longjmp(foo, 1);
	PANIC("_longjmp");
}

void *
jump(arg)
	void *arg;
{
	jmp_buf foo;

	reached = 0;
	if (setjmp(foo)) {
		ASSERT(reached);
		return NULL;
	}
	reached = 1;
	longjmp(foo, 1);
	PANIC("longjmp");
}

int
main()
{
	pthread_t child;
	void *res;

	printf("jumping in main thread\n");
	(void)jump(NULL);
	printf("_jumping in main thread\n");
	(void)_jump(NULL);

	printf("jumping in child thread\n");
	CHECKr(pthread_create(&child, NULL, jump, NULL));
	CHECKr(pthread_join(child, &res));

	printf("_jumping in child thread\n");
	CHECKr(pthread_create(&child, NULL, _jump, NULL));
	CHECKr(pthread_join(child, &res));

	SUCCEED;
}