libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] Sharing per-thread resources between connections


From: Carlos Eduardo Moreira dos Santos
Subject: Re: [libmicrohttpd] Sharing per-thread resources between connections
Date: Tue, 12 Aug 2014 17:36:15 -0300

__thread keyword is simple to use, but I have to open one socket per thread, so I used pthread_once and also pthread_key_create to close it. The only disadvantage I noticed is running pthread_once in every access handler callback call. I don't know the details, but pthread_once should be fast enough to discard my code, isn't it?

Best,
Carlos Eduardo


On Thu, Jul 3, 2014 at 5:05 AM, Christian Grothoff <address@hidden> wrote:
Well, pthread_key_create() also works, I guess, but I was thinking about
a slightly more lightweight method:

http://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Thread-Local.html

But both should work, and the best choice may really depend on your
application and its intended environment.


Happy hacking!

Christian

On 07/03/2014 09:58 AM, Carlos Eduardo Moreira dos Santos wrote:
> I googled and found pthread_key_create(). Is that what you meant? I'm
> glad to know I don't need to maintain a fork :). Thank you.
>
>
> On Tue, Jul 1, 2014 at 1:38 AM, Christian Grothoff <address@hidden
> <mailto:address@hidden>> wrote:
>
>     On 06/30/2014 06:30 PM, Carlos Eduardo Moreira dos Santos wrote:
>     > Hi,
>     >
>     > I'm using zeromq between a request and a response. Its socket is not
>     > thread-safe and that's one of the reasons I chose
>     MHD_USE_SELECT_INTERNALLY.
>     > As I am also using a thread pool, I have different sockets for
>     each thread.
>     > It is expensive to open and close a socket in every connection and
>     I would
>     > like to share a socket between all same-thread connections. I
>     didn't find a
>     > way to do it, so I made a small change in the code
>     >
>     <https://github.com/cemsbr/libmicrohttpd/commit/3151eff47553a8a93db7fb3355366b31aed2b262>
>     > in order to get the thread number (starting from 0) from the
>     connection
>     > daemon. Thus, I can initialize an array of sockets only once (in
>     the main
>     > function) and have them indexed by the thread number to be
>     accessed later.
>     >
>     > As a side effect, I have to include internal.h, but it is working as
>     > expected. Was there a better way of doing this that I haven't noticed?
>
>     You might want to just use a thread-local variable to hold your
>     connection.
>
>     My 1 cent ;-).
>
>     Christian
>
>


reply via email to

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