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
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to