Last change
on this file since 109 was 109, checked in by cheese, 11 years ago |
#1 add typical data structure algorithms (linked-list / queue / stak) and rename symbol for context of each modules
|
File size:
878 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 |
|
---|
9 | CF_Mutex_Ctx globalMutex;
|
---|
10 |
|
---|
11 | int 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 |
|
---|
25 | int main (void) {
|
---|
26 | CF_Thread_Ctx tid[10];
|
---|
27 | int i = 0;
|
---|
28 |
|
---|
29 | if (CF_Mutex_CreateCtx (&globalMutex) < 0) {
|
---|
30 | // error
|
---|
31 | }
|
---|
32 |
|
---|
33 | for (i = 0 ; i < 10 ; i++) {
|
---|
34 | if (CF_Thread_CreateCtx (&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_DestroyCtx (&tid[i]) < 0) {
|
---|
47 | // error
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | if (CF_Mutex_DestoryCtx (&globalMutex) < 0) {
|
---|
52 | // error
|
---|
53 | }
|
---|
54 | return 0;
|
---|
55 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.