[go: up one dir, main page]

File: s-thread.c

package info (click to toggle)
uftrace 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,212 kB
  • sloc: ansic: 53,313; python: 9,846; makefile: 838; asm: 703; cpp: 602; sh: 560; javascript: 191
file content (55 lines) | stat: -rw-r--r-- 817 bytes parent folder | download | duplicates (2)
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
/*
 * This is a basic test that checks uftrace can trace functions
 * properly within a multi-thread environment.
 */
#include <pthread.h>
#include <stdlib.h>

#define NUM_THREAD 4

static int a(void *);
static int b(void *);
static int c(void *);

static int a(void *arg)
{
	return b(arg) - 1;
}

static int b(void *arg)
{
	return c(arg) + 1;
}

static int c(void *arg)
{
	return *(int *)arg;
}

static void *foo(void *arg)
{
	return (void *)(long)a(arg);
}

int main(int argc, char *argv[])
{
	int i;
	int n = 10;
	int ret = 0;
	void *v;
	pthread_t t[NUM_THREAD];

	if (argc > 1)
		n = atoi(argv[1]);

	for (i = 0; i < NUM_THREAD; i++)
		pthread_create(&t[i], NULL, foo, &n);
	for (i = 0; i < NUM_THREAD; i++) {
		pthread_join(t[i], &v);
		ret += (long)v;
	}

	if (n * NUM_THREAD != ret)
		return ret;
	return 0;
}