1
0
Fork 0
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:
winlin 2014-06-28 10:57:58 +08:00
parent efed34301c
commit a3f9aa7e1e
6 changed files with 19 additions and 2 deletions

View file

@ -242,6 +242,7 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/> * 2013-10-17, Created.<br/>
## History ## History
* v1.0, 2014-06-25, fix [#110](https://github.com/winlinvip/simple-rtmp-server/issues/110), thread start segment fault, thread cycle stop destroy thread. 0.9.136
* v1.0, 2014-06-25, fix [#109](https://github.com/winlinvip/simple-rtmp-server/issues/109), fix the system jump time, adjust system startup time. 0.9.135 * v1.0, 2014-06-25, fix [#109](https://github.com/winlinvip/simple-rtmp-server/issues/109), fix the system jump time, adjust system startup time. 0.9.135
* <strong>v1.0, 2014-06-27, [1.0 mainline5(0.9.134)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.mainline5) released. 41573 lines.</strong> * <strong>v1.0, 2014-06-27, [1.0 mainline5(0.9.134)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.mainline5) released. 41573 lines.</strong>
* v1.0, 2014-06-27, SRS online 30days with RTMP/HLS. * v1.0, 2014-06-27, SRS online 30days with RTMP/HLS.

View file

@ -70,6 +70,7 @@ heartbeat {
# { # {
# "summaries": summaries object. # "summaries": summaries object.
# } # }
# @remark: optional config.
# default: off # default: off
summaries off; summaries off;
} }

View file

@ -910,7 +910,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
if ((ret = conn->start()) != ERROR_SUCCESS) { if ((ret = conn->start()) != ERROR_SUCCESS) {
return ret; return ret;
} }
srs_verbose("conn started success ."); srs_verbose("conn started success.");
srs_verbose("accept client finished. conns=%d, ret=%d", (int)conns.size(), ret); srs_verbose("accept client finished. conns=%d, ret=%d", (int)conns.size(), ret);

View file

@ -67,6 +67,12 @@ SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, boo
loop = false; loop = false;
_cid = -1; _cid = -1;
_joinable = joinable; _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() SrsThread::~SrsThread()
@ -102,6 +108,9 @@ int SrsThread::start()
st_usleep(10 * SRS_TIME_MILLISECONDS); st_usleep(10 * SRS_TIME_MILLISECONDS);
} }
// now, cycle thread can run.
can_run = true;
return ret; return ret;
} }
@ -143,6 +152,11 @@ void SrsThread::thread_cycle()
srs_assert(handler); srs_assert(handler);
handler->on_thread_start(); 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) { while (loop) {
if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) { if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) {
srs_warn("thread on before cycle failed, ignored and retry, ret=%d", ret); srs_warn("thread on before cycle failed, ignored and retry, ret=%d", ret);

View file

@ -88,6 +88,7 @@ private:
st_thread_t tid; st_thread_t tid;
int _cid; int _cid;
bool loop; bool loop;
bool can_run;
bool _joinable; bool _joinable;
private: private:
ISrsThreadHandler* handler; ISrsThreadHandler* handler;

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR "0" #define VERSION_MAJOR "0"
#define VERSION_MINOR "9" #define VERSION_MINOR "9"
#define VERSION_REVISION "135" #define VERSION_REVISION "136"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info. // server info.
#define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_KEY "SRS"