Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-10-26 13:55:37 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
79ab9f05f3abe70dafdfbbc8b83d8dcda2035eb3
79ab9f05
1 parent
388305f4
refs #182: update the st, use cond and mutex.
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
41 行增加
和
3 行删除
trunk/research/st/srs.c
trunk/research/st/srs.c
查看文件 @
79ab9f0
...
...
@@ -5,10 +5,22 @@
#define srs_trace(msg, ...) printf(msg, ##__VA_ARGS__);printf("\n")
st_cond_t
cond
=
NULL
;
st_mutex_t
mutex
=
NULL
;
void
*
pfn
(
void
*
arg
)
{
st_sleep
(
1
);
srs_trace
(
"st thread is ok"
);
st_usleep
(
100
*
1000
);
st_cond_signal
(
cond
);
st_mutex_lock
(
mutex
);
srs_trace
(
"2. st mutex is ok"
);
st_mutex_unlock
(
mutex
);
st_usleep
(
100
*
1000
);
srs_trace
(
"3. st thread is ok"
);
st_cond_signal
(
cond
);
return
NULL
;
}
...
...
@@ -23,14 +35,40 @@ int main(int argc, char** argv)
srs_trace
(
"st_init failed"
);
return
-
1
;
}
if
((
cond
=
st_cond_new
())
==
NULL
)
{
srs_trace
(
"st_cond_new failed"
);
return
-
1
;
}
if
((
mutex
=
st_mutex_new
())
==
NULL
)
{
srs_trace
(
"st_mutex_new failed"
);
return
-
1
;
}
if
(
!
st_thread_create
(
pfn
,
NULL
,
0
,
0
))
{
srs_trace
(
"st_thread_create failed"
);
return
-
1
;
}
srs_trace
(
"st is ok"
);
// lock mutex to control thread.
st_mutex_lock
(
mutex
);
// wait thread to ready.
st_cond_wait
(
cond
);
srs_trace
(
"1. st cond is ok"
);
// release mutex to control thread
st_usleep
(
100
*
1000
);
st_mutex_unlock
(
mutex
);
// wait thread to exit.
st_cond_wait
(
cond
);
srs_trace
(
"4. st is ok"
);
// cleanup.
st_cond_destroy
(
cond
);
st_mutex_destroy
(
mutex
);
st_thread_exit
(
NULL
);
return
0
;
...
...
请
注册
或
登录
后发表评论