ufairiya / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

mg_stop sleeps for 1 second #112

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This loop inside mg_stop()

    /* Wait until mg_fini() stops */
    while (ctx->stop_flag != 2)
        (void) sleep(1);

Was making our application delay on exit. Changing the sleep(1) to usleep
(250) made things faster and could provide more fine grained timing and 
waste less cycles while waiting for worker threads to finish.

Original issue reported on code.google.com by pedro.na...@gmail.com on 6 Jan 2010 at 3:05

GoogleCodeExporter commented 9 years ago
I meant usleep( 250 * 1000 );

Original comment by pedro.na...@gmail.com on 15 Jan 2010 at 1:27

GoogleCodeExporter commented 9 years ago
You can also better still use:
struct timeval  tv;
ctx->stop_flag = 1;
/* Wait until mg_fini() stops */
    while (ctx->stop_flag != 2)
    {
        tv.tv_sec = 0;
        tv.tv_usec = 500 * 1000;
        (void) select(1, NULL, NULL, NULL, &tv);//usleep(500 * 1000);//sleep(1);
    }

Original comment by rokkamr...@gmail.com on 1 Sep 2010 at 12:19

GoogleCodeExporter commented 9 years ago
Submitted 
http://code.google.com/p/mongoose/source/detail?r=ac06624519bfef989264a299f08149
c4183d2f37

Thanks.

Original comment by valenok on 29 Nov 2010 at 1:39