thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Slee <ms...@facebook.com>
Subject RE: TThreadPoolServer thread safety
Date Sat, 06 Nov 2010 01:02:31 GMT
You will have to use a thread-local store construct for this. This has definitely come up before
and I'm pretty sure there are some patches out there for it, in one capacity or another.

If your buffers are of a fixed, reasonable size, I'd recommend just sticking them on the stack
(as local variables in the handler method) -- though it sounds from your message like this
is not the case and you want to avoid allocations.

If writes to your buffer are rare, a read-write lock might suffice. Otherwise, I'd probably
take a look at boost's TLS mechanism: http://www.boost.org/doc/libs/1_39_0/doc/html/thread/thread_local_storage.html

I haven't been working at this level of C++ for quite a while, someone else on the list probably
has better recommendation. As far as I'm aware, we don't have an API for this in the Thrift
library itself.

Any other opinions here?

Cheers,
mcslee

-----Original Message-----
From: Michi Mutsuzaki [mailto:michim@yahoo-inc.com] 
Sent: Friday, November 05, 2010 5:25 PM
To: user@thrift.apache.org
Subject: Re: TThreadPoolServer thread safety

Thank you for your reply, Mark.

Is there a way to have per-thread data? For example, can I allocate a buffer
for each thread in the threadpool? Otherwise, each thread needs to
allocate/deallocate a buffer in the handler function for each request.

Thanks!
--Michi

On 11/5/10 4:16 PM, "Mark Slee" <mslee@facebook.com> wrote:

> TThreadPoolServer is *not* thread-safe. The threads it creates are not
> synchronized in any way.
> 
> You must implement thread-safety yourself if you are sharing any data across
> request handlers.
> 
> -----Original Message-----
> From: Michi Mutsuzaki [mailto:michim@yahoo-inc.com]
> Sent: Friday, November 05, 2010 3:52 PM
> To: user@thrift.apache.org
> Subject: TThreadPoolServer thread safety
> 
> Hi,
> 
> I'm using TThreadPoolServer with C++. Does my handler need to be
> thread-safe? More specifically, my handler has a static member, and I'm
> wondering if I need to protect it using a mutex.
> 
> Thanks!
> --Michi
> 
> 


Mime
View raw message