From 6ed9e03449097cea58189df53cd53aaf061b3f59 Mon Sep 17 00:00:00 2001 From: myaaaaaaaaa <103326468+myaaaaaaaaa@users.noreply.github.com> Date: Wed, 22 Feb 2023 16:49:48 -0500 Subject: Fix data races in startup/teardown (cherry picked from commit d337ed1c64de89ed410cfe208ea162e4cd4ae503) --- core/io/ip.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core/io/ip.cpp') diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 28b7037120..65728f34f6 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -75,7 +75,7 @@ struct _IP_ResolverPrivate { Semaphore sem; Thread thread; - bool thread_abort = false; + SafeFlag thread_abort; void resolve_queues() { for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { @@ -111,7 +111,7 @@ struct _IP_ResolverPrivate { static void _thread_function(void *self) { _IP_ResolverPrivate *ipr = static_cast<_IP_ResolverPrivate *>(self); - while (!ipr->thread_abort) { + while (!ipr->thread_abort.is_set()) { ipr->sem.wait(); ipr->resolve_queues(); } @@ -343,12 +343,12 @@ IP::IP() { singleton = this; resolver = memnew(_IP_ResolverPrivate); - resolver->thread_abort = false; + resolver->thread_abort.clear(); resolver->thread.start(_IP_ResolverPrivate::_thread_function, resolver); } IP::~IP() { - resolver->thread_abort = true; + resolver->thread_abort.set(); resolver->sem.post(); resolver->thread.wait_to_finish(); -- cgit v1.2.3