summaryrefslogtreecommitdiff
path: root/pthread.c
blob: 33ab9ec0ea17aecdb026d7096982cd17f41721a7 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>

void *emptyfunc(void *dummy)
{
	return 0;
}

size_t b_pthread_createjoin_serial1(void *dummy)
{
	size_t i;
	pthread_t td;
	for (i=0; i<2500; i++) {
		pthread_create(&td, 0, emptyfunc, 0);
		pthread_join(td, &dummy);
	}
	return 0;
}

size_t b_pthread_createjoin_serial2(void *dummy)
{
	size_t i, j;
	pthread_t td[50];
	for (j=0; j<50; j++) {
		for (i=0; i<sizeof td/sizeof *td; i++)
			pthread_create(td+i, 0, emptyfunc, 0);
		for (i=0; i<sizeof td/sizeof *td; i++)
			pthread_join(td[i], &dummy);
	}
	return 0;
}

size_t b_pthread_create_serial1(void *dummy)
{
	size_t i;
	pthread_attr_t attr;
	pthread_t td;
	pthread_attr_init(&attr);
	pthread_attr_setstacksize(&attr, 16384);
	for (i=0; i<2500; i++)
		pthread_create(&td, &attr, emptyfunc, 0);
	return 0;
}

void *lockunlock(void *mut)
{
	size_t i;
	for (i=0; i<1000000; i++) {
		pthread_mutex_lock(mut);
		pthread_mutex_unlock(mut);
	}
	return 0;
}

size_t b_pthread_uselesslock(void *dummy)
{
	pthread_t td;
	pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
	pthread_create(&td, 0, lockunlock, &mut);
	pthread_join(td, &dummy);
	return 0;
}

size_t b_pthread_createjoin_minimal1(void *dummy)
{
	size_t i;
	pthread_t td;
	pthread_attr_t a;
	pthread_attr_init(&a);
	pthread_attr_setstacksize(&a, sysconf(_SC_PAGESIZE));
	pthread_attr_setguardsize(&a, 0);
	for (i=0; i<2500; i++) {
		pthread_create(&td, &a, emptyfunc, 0);
		pthread_join(td, &dummy);
	}
	return 0;
}

size_t b_pthread_createjoin_minimal2(void *dummy)
{
	size_t i, j;
	pthread_t td[50];
	pthread_attr_t a;
	pthread_attr_init(&a);
	pthread_attr_setstacksize(&a, sysconf(_SC_PAGESIZE));
	pthread_attr_setguardsize(&a, 0);
	for (j=0; j<50; j++) {
		for (i=0; i<sizeof td/sizeof *td; i++)
			pthread_create(td+i, &a, emptyfunc, 0);
		for (i=0; i<sizeof td/sizeof *td; i++)
			pthread_join(td[i], &dummy);
	}
	return 0;
}