[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Help with Libevent multi-threaded HTTP server



On Sun, Dec 28, 2014 at 01:30:36PM +0000, Gerry Sweeney wrote:
> Hi,
> 
> I am new to lib event so please forgive me if this is a noob question. I ran into a problem usinglib event and wonder if anyone can help
> 
> My question I hope is very simple: -
> 
> I am trying to create a simple multi-threaded HTTP server.  
> 
> I create and bind a non-blocking listening socket on port 8080, then for each thread I want to create to process HTTP requests I call the following
> 
> event_base_new()
> evhttp_new()
> evhttp_accept_socket_with_handle()
> evhttp_set_gencb()
> pthread_create(my_http_worker_thread_fn, base);
> 
> Then in the thread function for each worker thread I call event_base_dispatch((struct event_base*)arg);
> 
> Everything works as expected and I can process HTTP requests. The problem I am having is shutting down cleanly. 
> 
> After my main thread creates the worker threads I wait for a return key press on getchar() so I can press return to shutdown, after which I call event_base_loopbreak() on each event base I created, then I call pthread_join() from my main thread on each worker thread handle to wait for all threads to complete. 
> 
> The problem is, after calling event_base_loopbreak() I am expecting event_base_dispatch() to return but it never does, looking at the call stack for each thread they all appear to be waiting for an event. So I end up stuck waiting for threads to end which never do.

The loop must breaks after event_base_loopbreak().

Could you try debug mode and analyze it's messages?
If you could write 50L code sample to reproduce this problem - I
could have a look.

Cheers,
Azat.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.