mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #110, thread start segment fault, thread cycle stop destroy thread. 0.9.136
This commit is contained in:
parent
efed34301c
commit
a3f9aa7e1e
6 changed files with 19 additions and 2 deletions
|
@ -67,6 +67,12 @@ SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, boo
|
|||
loop = false;
|
||||
_cid = -1;
|
||||
_joinable = joinable;
|
||||
|
||||
// in start(), the thread cycle method maybe stop and remove the thread itself,
|
||||
// and the thread start() is waiting for the _cid, and segment fault then.
|
||||
// @see https://github.com/winlinvip/simple-rtmp-server/issues/110
|
||||
// thread will set _cid, callback on_thread_start(), then wait for the can_run signal.
|
||||
can_run = false;
|
||||
}
|
||||
|
||||
SrsThread::~SrsThread()
|
||||
|
@ -102,6 +108,9 @@ int SrsThread::start()
|
|||
st_usleep(10 * SRS_TIME_MILLISECONDS);
|
||||
}
|
||||
|
||||
// now, cycle thread can run.
|
||||
can_run = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -143,6 +152,11 @@ void SrsThread::thread_cycle()
|
|||
srs_assert(handler);
|
||||
handler->on_thread_start();
|
||||
|
||||
// wait for cid to ready, for parent thread to get the cid.
|
||||
while (!can_run && loop) {
|
||||
st_usleep(10 * SRS_TIME_MILLISECONDS);
|
||||
}
|
||||
|
||||
while (loop) {
|
||||
if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) {
|
||||
srs_warn("thread on before cycle failed, ignored and retry, ret=%d", ret);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue