Fix race in defaultLoop

This commit is contained in:
Alex Hultman
2019-03-01 16:14:53 +01:00
parent 2afe6a6efb
commit 940980f501
+2 -1
View File
@@ -24,6 +24,7 @@
#include <libusockets_new.h>
#include <iostream>
#include <atomic>
namespace uWS {
struct Loop {
@@ -87,7 +88,7 @@ public:
static Loop *defaultLoop() {
/* Deliver and attach the default loop to the first thread who calls us */
static thread_local bool ownsDefaultLoop;
static Loop *defaultLoop;
static std::atomic<Loop *> defaultLoop;
if (!defaultLoop) {
ownsDefaultLoop = true;
defaultLoop = create(true);