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
|
Rev | Line | |
---|
[35] | 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 globalMutex;
|
---|
| 10 |
|
---|
[57] | 11 | int worker (void * arg) {
|
---|
[35] | 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 |
|
---|
[57] | 22 | return 0;
|
---|
[35] | 23 | }
|
---|
| 24 |
|
---|
| 25 | int 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.