[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] threading model question

From: Christian Grothoff
Subject: Re: [libmicrohttpd] threading model question
Date: Fri, 28 Oct 2011 15:01:46 +0200
User-agent: KMail/1.13.7 (Linux/2.6.39-1-amd64; KDE/4.6.5; x86_64; ; )

On Thursday, October 27, 2011 09:29:52 PM Sven Geggus wrote:
> Hello,
> I try to use libmicrohttpd in conjunction with a main function which
> acquires data in an endless loop (currently every 4 seconds).
> What I want to achieve is that all the current client connections
> with an active request for this data will block until it is
> available.
> Thus I decided to go for the MHD_USE_THREAD_PER_CONNECTION model.

Well, that's technically not required.  You can simply integrate your data-
polling loop into the external select loop of MHD and in the response 
callbacks for data-aquisition return 0 (which will be interpreted as "no data 
available yet, try again in the next round of select").  Note that MHD will 
then NOT put the respective sockets into your write set, so you would not end 
up busy-waiting.

> I tried to use pthread_cond_wait and pthread_cond_broadcast to
> implement the blocking scheme, but unfortunately this does not work
> as expected when more than one client is in use.

I think to begin with, you need a mutex to protect your condition variable
( has sample code)
But this won't be all -- you'd need to count the number of active clients, and 
to make sure to signal them all once, you'll need a second semaphore to 
implement a barrier. Threads are complicated (and this is not an MHD-specific 
problem).  It might be easier to use the external-select mode for this 

Happy hacking,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]