正在显示
1 个修改的文件
包含
13 行增加
和
0 行删除
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | st_mutex_t sync_start = NULL; | 8 | st_mutex_t sync_start = NULL; |
| 9 | st_cond_t sync_cond = NULL; | 9 | st_cond_t sync_cond = NULL; |
| 10 | st_mutex_t sync_mutex = NULL; | 10 | st_mutex_t sync_mutex = NULL; |
| 11 | +st_cond_t sync_end = NULL; | ||
| 11 | 12 | ||
| 12 | void* sync_master(void* arg) | 13 | void* sync_master(void* arg) |
| 13 | { | 14 | { |
| @@ -50,11 +51,15 @@ void* sync_slave(void* arg) | @@ -50,11 +51,15 @@ void* sync_slave(void* arg) | ||
| 50 | st_cond_wait(sync_cond); | 51 | st_cond_wait(sync_cond); |
| 51 | srs_trace("4. st is ok"); | 52 | srs_trace("4. st is ok"); |
| 52 | 53 | ||
| 54 | + st_cond_signal(sync_end); | ||
| 55 | + | ||
| 53 | return NULL; | 56 | return NULL; |
| 54 | } | 57 | } |
| 55 | 58 | ||
| 56 | int sync_test() | 59 | int sync_test() |
| 57 | { | 60 | { |
| 61 | + srs_trace("sync test: start"); | ||
| 62 | + | ||
| 58 | if ((sync_start = st_mutex_new()) == NULL) { | 63 | if ((sync_start = st_mutex_new()) == NULL) { |
| 59 | srs_trace("st_mutex_new sync_start failed"); | 64 | srs_trace("st_mutex_new sync_start failed"); |
| 60 | return -1; | 65 | return -1; |
| @@ -65,6 +70,11 @@ int sync_test() | @@ -65,6 +70,11 @@ int sync_test() | ||
| 65 | srs_trace("st_cond_new cond failed"); | 70 | srs_trace("st_cond_new cond failed"); |
| 66 | return -1; | 71 | return -1; |
| 67 | } | 72 | } |
| 73 | + | ||
| 74 | + if ((sync_end = st_cond_new()) == NULL) { | ||
| 75 | + srs_trace("st_cond_new end failed"); | ||
| 76 | + return -1; | ||
| 77 | + } | ||
| 68 | 78 | ||
| 69 | if ((sync_mutex = st_mutex_new()) == NULL) { | 79 | if ((sync_mutex = st_mutex_new()) == NULL) { |
| 70 | srs_trace("st_mutex_new mutex failed"); | 80 | srs_trace("st_mutex_new mutex failed"); |
| @@ -84,6 +94,9 @@ int sync_test() | @@ -84,6 +94,9 @@ int sync_test() | ||
| 84 | // run all threads. | 94 | // run all threads. |
| 85 | st_mutex_unlock(sync_start); | 95 | st_mutex_unlock(sync_start); |
| 86 | 96 | ||
| 97 | + st_cond_wait(sync_end); | ||
| 98 | + srs_trace("sync test: end"); | ||
| 99 | + | ||
| 87 | return 0; | 100 | return 0; |
| 88 | } | 101 | } |
| 89 | 102 |
-
请 注册 或 登录 后发表评论