thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Slee <>
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:

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?


-----Original Message-----
From: Michi Mutsuzaki [] 
Sent: Friday, November 05, 2010 5:25 PM
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.


On 11/5/10 4:16 PM, "Mark Slee" <> 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 []
> Sent: Friday, November 05, 2010 3:52 PM
> To:
> 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

View raw message