Fix race in defaultLoop
This commit is contained in:
+2
-1
@@ -24,6 +24,7 @@
|
|||||||
#include <libusockets_new.h>
|
#include <libusockets_new.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace uWS {
|
namespace uWS {
|
||||||
struct Loop {
|
struct Loop {
|
||||||
@@ -87,7 +88,7 @@ public:
|
|||||||
static Loop *defaultLoop() {
|
static Loop *defaultLoop() {
|
||||||
/* Deliver and attach the default loop to the first thread who calls us */
|
/* Deliver and attach the default loop to the first thread who calls us */
|
||||||
static thread_local bool ownsDefaultLoop;
|
static thread_local bool ownsDefaultLoop;
|
||||||
static Loop *defaultLoop;
|
static std::atomic<Loop *> defaultLoop;
|
||||||
if (!defaultLoop) {
|
if (!defaultLoop) {
|
||||||
ownsDefaultLoop = true;
|
ownsDefaultLoop = true;
|
||||||
defaultLoop = create(true);
|
defaultLoop = create(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user