Skip to content

Commit

Permalink
Fixed critical bug where the popDestruct's destructor was not locking…
Browse files Browse the repository at this point in the history
… while pop-ing from the deque.
  • Loading branch information
abdulkareem-siddiq committed Oct 7, 2021
1 parent f7eb443 commit 9295371
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions nuget/SiddiqSoft.asynchrony-lib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<version>$VERSION$</version>
<authors>SiddiqSoft</authors>
<description>Add asynchrony to your apps</description>
<tags>jthread thread async pool deque cpp20 native nativepackage cpp</tags>
<tags>jthread thread periodic timer async pool deque cpp20 native nativepackage cpp</tags>
<projectUrl>https://github.com/SiddiqSoft/asynchrony-lib</projectUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<license type="expression">BSD-3-Clause</license>
<icon>docs\Siddiq-Software-Avatar.png</icon>
<readme>docs\README.md</readme>
<icon>docs\Siddiq-Software-Avatar.png</icon>
<readme>docs\README.md</readme>
<releaseNotes></releaseNotes>
<copyright>Copyright (c) 2021 Siddiq Software LLC</copyright>
<!-- Dependencies -->
Expand All @@ -36,7 +36,7 @@
<file src="..\src\*.hpp" target="build\native\include\siddiqsoft\" />
<file src="Siddiq-Software-Avatar.png" target="docs\" />
<file src="..\README.md" target="docs\" />

<!-- MSBuild .targets files -->
<file src="SiddiqSoft.asynchrony-lib.targets" target="build\native" />
</files>
Expand Down
10 changes: 5 additions & 5 deletions src/simple_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ namespace siddiqsoft
#endif

private:
std::vector<std::jthread> workers {};
std::function<void(T&)> callback;
std::counting_semaphore<512> signal {0};
std::deque<T> items {};
std::shared_mutex items_mutex;
std::vector<std::jthread> workers {};
std::function<void(T&)> callback;
std::counting_semaphore<> signal {0};
std::deque<T> items {};
std::shared_mutex items_mutex;
/// @brief This is the interval we wait on the signal. It starts off with 500ms and when the thread is to shutdown, it is
/// set to 1ms.
std::chrono::milliseconds signalWaitInterval {1500};
Expand Down
5 changes: 3 additions & 2 deletions src/simple_worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace siddiqsoft
/// @brief Pop the front of the queue upon destructor invocation
~popOnDestruct() noexcept
{
std::unique_lock<std::shared_mutex> myWriterLock(parentMutex);
if (!parentDeque.empty()) parentDeque.pop_front();
}

Expand Down Expand Up @@ -172,8 +173,8 @@ namespace siddiqsoft
std::deque<T> items {};
/// @brief Mutex to protect the items
std::shared_mutex items_mutex {};
/// @brief Semaphore with initial max of 128 items (backlog)
std::counting_semaphore<512> signal {0};
/// @brief Semaphore with default max signals.
std::counting_semaphore<> signal {0};
/// @brief This is the interval we wait on the signal. It starts off with 500ms and when the thread is to shutdown, it is
/// set to 1ms.
std::chrono::milliseconds signalWaitInterval {1500};
Expand Down

0 comments on commit 9295371

Please sign in to comment.