Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netreplay: Use wzThread* functions instead of std::thread #3544

Merged

Conversation

past-due
Copy link
Member

@past-due past-due commented Nov 28, 2023

To avoid std::thread::~thread() calling std::terminate() upon non-graceful shutdown.

To avoid std::thread::~thread() calling std::terminate() upon non-graceful shutdown.
@past-due past-due added this to the 4.4.2 milestone Nov 28, 2023
@@ -59,14 +59,15 @@ typedef std::vector<uint8_t> SerializedNetMessagesBuffer;
static moodycamel::BlockingReaderWriterQueue<SerializedNetMessagesBuffer> serializedBufferWriteQueue(256);
static SerializedNetMessagesBuffer latestWriteBuffer;
static size_t minBufferSizeToQueue = DefaultReplayBufferSize;
static std::unique_ptr<wz::thread> saveThread;
static WZ_THREAD *saveThread = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use std::unique_ptr<WZ_THREAD>?

Copy link
Member Author

@past-due past-due Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WZ_THREAD instances should only be created and managed by the wzThread* functions. (They wrap SDL Threads.)

Also, this is one of those things that we actually want to "leak" on a non-graceful shutdown (to avoid various downstream effects that could lead to crash logs that aren't very useful - like in the std::thread destructor case.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, you still should be able to adopt the raw pointer you get from wzThreadCreate and then just declare a std::unique_ptr with a custom deleter, which will call wzThreadJoin instead of the default delete.

Copy link
Member Author

@past-due past-due Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like my edit stepped on your comment - we actually want this to "leak" on a non-graceful shutdown. (i.e. We don't want to join + wait.)

@past-due past-due merged commit 3c71f87 into Warzone2100:master Nov 28, 2023
35 checks passed
@past-due past-due deleted the 2023_11_netreplay_thread_change_1 branch November 28, 2023 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants