Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CThreadPool
// synchronization
std::mutex queue_mutex;
std::condition_variable condition;
bool stop;
bool stop = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Needs review...

Copy link
Copy Markdown
Member

@softins softins May 11, 2026

Choose a reason for hiding this comment

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

After some thought, I've concluded that it is because CThreadPool has two constructors:

  • CThreadPool() = default
  • CThreadPool(size_t)
    and only the size_t version has a constructor initialisation for stop(false), a few lines further down. The default constructor doesn't, and therefore if that constructor were used, stop would start uninitialised.

In fact, it would appear that in the code, the CThreadPool constructor is only ever called with the size_t argument, in server.cpp.

So in that case, instead of the above in-class initialisation, I would remove the default constructor declaration and check that the code still compiles (it should, unless I've overlooked something).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So in that case, instead of the above in-class initialisation, I would remove the default constructor declaration and check that the code still compiles (it should, unless I've overlooked something).

Yes, I've tested compilation with the line CThreadPool() = default; removed, and it still builds fine. So I would recommend that is the best solution, as it doesn't seem to make sense to create a thread pool without specifying a number of threads.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If one of the two constructors is never needed, removing the unused option makes sense to me.

Also, Gemini mentions Brace Initialization, introduced in C++ v11, which assures zero-initialization.

};

// the constructor just launches some amount of workers
Expand Down