[zeromq-dev] libzmq and TLS (thread local static) ?

Laurent Alebarde l.alebarde at free.fr
Wed Jan 29 14:39:46 CET 2014


Hi Devs,

I assume every function in the libzmq API is thread safe, but there are 
static variables in the code and no use of __thread ? Are all static 
variables defined in libzmq global to all threads ?

If I add a static variable which need to be thread local, say inside 
zmq::proxy, is it all right to add something like this in zmq.h ?

#if (__cplusplus > 199711L) || (defined(__STDCXX_VERSION__) && 
(__STDCXX_VERSION__ >= 201001L))
#define _TTHREAD_CPP0X_
#endif

#if !defined(_TTHREAD_CPP0X_) && !defined(thread_local)
#if defined(__GNUC__) || defined(__INTEL_COMPILER) || 
defined(__SUNPRO_CC) || defined(__IBMCPP__)
#define thread_local __thread
#else
#define thread_local __declspec(thread)
#endif
#endif

Found here: 
https://github.com/DFHack/dfhack/blob/master/depends/tthread/tinythread.h
About __thread and thread_local: 
http://stackoverflow.com/questions/7047226/using-thread-in-c0x

Usage:

static __thread char *p;

Cheers,


Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140129/38beb740/attachment.htm>


More information about the zeromq-dev mailing list