source: libcf/trunk/test/thread.c@ 66

Last change on this file since 66 was 66, checked in by cheese, 11 years ago

#1 add codec module (bin <-> hex-string)

File size: 858 bytes
Line 
1/**
2 * @file thread.c
3 * @author myusgun <myusgun@gmail.com>
4 */
5#include "cf_thread.h"
6
7#include <stdio.h>
8
9CF_Mutex globalMutex;
10
11int worker (void * arg) {
12 if (CF_Mutex_Lock (&globalMutex) < 0) { // for critical section
13 // error
14 }
15
16 fprintf (stderr, "here is critical section !\n");
17
18 if (CF_Mutex_Unlock (&globalMutex) < 0) { // for critical section
19 // error
20 }
21
22 return 0;
23}
24
25int main (void) {
26 CF_Thread tid[10];
27 int i = 0;
28
29 if (CF_Mutex_Create (&globalMutex) < 0) {
30 // error
31 }
32
33 for (i = 0 ; i < 10 ; i++) {
34 if (CF_Thread_Create (&tid[i], worker, NULL) < 0) {
35 // error
36 }
37 }
38
39 for (i = 0 ; i < 10 ; i++) {
40 if (CF_Thread_Join (&tid[i]) < 0) { // block
41 // error
42 }
43 }
44
45 for (i = 0 ; i < 10 ; i++) {
46 if (CF_Thread_Release (&tid[i]) < 0) {
47 // error
48 }
49 }
50
51 if (CF_Mutex_Destory (&globalMutex) < 0) {
52 // error
53 }
54 return 0;
55}
Note: See TracBrowser for help on using the repository browser.