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

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

#1 fix thread interface

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