mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

mg_stop is blocked in my C++ codes!

Open sinotitan opened this issue 13 years ago • 4 comments

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; } }

sinotitan avatar Oct 28 '13 12:10 sinotitan

my os:win7 32bit

sinotitan avatar Oct 29 '13 01:10 sinotitan

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);

sinotitan avatar Oct 29 '13 02:10 sinotitan

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

sinotitan avatar Oct 31 '13 04:10 sinotitan

Pushed https://github.com/cesanta/mongoose/commit/bba29d32ce7d3982bd519898feff3c6b2991d5ea That should fix the problem. Please verify.

Thanks for reporting!

cpq avatar Dec 05 '13 10:12 cpq