File: threads.c

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (53 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (3)
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
#include <r_th.h>
#include <r_util.h>

int looper(struct r_th_t *th) {
	int i;
	int *ctr = th->user;
	for (i=0;i<9999;i++) {
		if (th->breaked)
			break;
		(*ctr)++;
		printf ("%d loop %d\r", i, *ctr);
		fflush (stdout);
#if __UNIX__
		sleep (1);
#endif
	}
	return 0; // do not loop
}

int test1() {
	int ctr = 0;
	struct r_th_t *th;

	th = r_th_new (&looper, &ctr, 0);
	th = r_th_new (&looper, &ctr, 0);
	//th = r_th_new (&looper, &ctr, 0);

#if __i386__ || __x86_64__
	asm ("int3");
#endif
	//r_th_start (th, R_TRUE);
	while (r_th_wait_async (th)) {
		printf ("\nwaiting...\n");
		fflush (stdout);
		r_sys_usleep (400);
		//	r_th_break(th);
	}
	printf ("\nfinished\n");
#if 0
	r_th_start(th, R_TRUE);
	sleep(1);
#endif
	/* wait and free */
	r_th_wait (th);
	r_th_free (th);

	printf ("\nresult %d\n", ctr);
	return 0;
}

int main() {
	return test1 ();
}