mg_stop is blocked in my C++ codes!
i embed mongoose in my c++ codes.but when i want to stop mongoose,mg_stop is blocked!
after debug,i find the following loop cannot go on... // Wait until mg_fini() stops while (ctx->stop_flag != 2) { (void) mg_sleep(10); }
who can tell me why?
my codes:
include "mongoose.h"
struct mg_context *g_mgctx = NULL;
// This function will be called by mongoose on every new request. static int event_handler(struct mg_event *event) {
// We do not handle any other event return 0; } void CLocalServerDlg::OnBnClickedBtnStart() { // List of options. Last element must be NULL. const char *options[] = {"listening_ports", "8181", NULL};
// Start the web server.
g_mgctx = mg_start(options, &event_handler, NULL);
}
void CLocalServerDlg::OnBnClickedBtnEndsvr() { if(g_mgctx) { mg_stop(g_mgctx); g_mgctx = NULL; } }
my os:win7 32bit
deadlock in master_thread()
(void) pthread_mutex_lock(&ctx->mutex); while (ctx->num_threads > 0) { (void) pthread_cond_wait(&ctx->cond, &ctx->mutex); } (void) pthread_mutex_unlock(&ctx->mutex);
i found how cause this problem. PulseEvent causes ms_stop() function to hang when the process runs in the VisualStudio debugger (observed on Windows XP SP3 VS 2008)
MSDN states that PulseEvent() "function is unreliable and should not be used. It exists mainly for backward compatibility" http://msdn.microsoft.com/en-us/library/ms684914%28v=vs.85%29.aspx
Pushed https://github.com/cesanta/mongoose/commit/bba29d32ce7d3982bd519898feff3c6b2991d5ea That should fix the problem. Please verify.
Thanks for reporting!