thread safety bug - lock when sending

This commit is contained in:
somdoron
2015-02-13 09:30:29 +02:00
parent 5d42fe1bf7
commit deaa89656f
3 changed files with 22 additions and 28 deletions

View File

@@ -88,7 +88,13 @@ namespace zmq
public:
inline mutex_t ()
{
int rc = pthread_mutex_init (&mutex, NULL);
int rc = pthread_mutexattr_init(&attr);
posix_assert (rc);
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
posix_assert (rc);
rc = pthread_mutex_init (&mutex, &attr);
posix_assert (rc);
}
@@ -96,6 +102,9 @@ namespace zmq
{
int rc = pthread_mutex_destroy (&mutex);
posix_assert (rc);
rc = pthread_mutexattr_destroy (&attr);
posix_assert (rc);
}
inline void lock ()
@@ -128,6 +137,7 @@ namespace zmq
private:
pthread_mutex_t mutex;
pthread_mutexattr_t attr;
// Disable copy construction and assignment.
mutex_t (const mutex_t&);