fix(Event): Event data race #3629

This commit is contained in:
Alex Fabijanic
2022-06-02 11:40:40 -05:00
parent db0e012f3f
commit fbdb6120aa
3 changed files with 12 additions and 8 deletions

View File

@@ -22,6 +22,7 @@
#include "Poco/Exception.h"
#include <pthread.h>
#include <errno.h>
#include <atomic>
namespace Poco {
@@ -38,10 +39,10 @@ protected:
void resetImpl();
private:
bool _auto;
volatile bool _state;
pthread_mutex_t _mutex;
pthread_cond_t _cond;
bool _auto;
std::atomic<bool> _state;
pthread_mutex_t _mutex;
pthread_cond_t _cond;
};
@@ -50,7 +51,7 @@ private:
//
inline void EventImpl::setImpl()
{
if (pthread_mutex_lock(&_mutex))
if (pthread_mutex_lock(&_mutex))
throw SystemException("cannot signal event (lock)");
_state = true;
if (pthread_cond_broadcast(&_cond))