Skip to content

Commit 9a57009

Browse files
committed
coro::thread_pool uses lockless mpmc queue
std::deque with std::mutex and std::condition_variable are easy to use but atrocious for performance. Using a relatively drop in replacement moodycamel::BlockingConcurrentQueue to speed up the scheduling of tasks onto a thread pool. Noted items: * a coroutine in a while(cond) { co_await tp->yield(); } loop where the thread_pool only has 1 executor thread causes an infinite loop, I've worked around this by using `queue.wait_dequeue_bulk_timed()` to guarantee multiple tasks get executed per executor loop, this is not done with multiple executor threads since we want to distribute the work more evently. Closes #404
1 parent f3ca220 commit 9a57009

File tree

10 files changed

+4915
-81
lines changed

10 files changed

+4915
-81
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ set(LIBCORO_SOURCE_FILES
114114
include/coro/concepts/promise.hpp
115115
include/coro/concepts/range_of.hpp
116116

117+
include/coro/detail/vendor/cameron314/concurrentqueue/concurrentqueue.h
118+
include/coro/detail/vendor/cameron314/concurrentqueue/lightweightsemaphore.h
119+
include/coro/detail/vendor/cameron314/concurrentqueue/blockingconcurrentqueue.h
120+
117121
include/coro/detail/awaiter_list.hpp
118122
include/coro/detail/task_self_deleting.hpp src/detail/task_self_deleting.cpp
119123
include/coro/detail/void_value.hpp
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
This license file applies to everything in this repository except that which
2+
is explicitly annotated as being written by other authors, i.e. the Boost
3+
queue (included in the benchmarks for comparison), Intel's TBB library (ditto),
4+
dlib::pipe (ditto),
5+
the CDSChecker tool (used for verification), the Relacy model checker (ditto),
6+
and Jeff Preshing's semaphore implementation (used in the blocking queue) which
7+
has a zlib license (embedded in lightweightsempahore.h).
8+
9+
---
10+
11+
Simplified BSD License:
12+
13+
Copyright (c) 2013-2016, Cameron Desrochers.
14+
All rights reserved.
15+
16+
Redistribution and use in source and binary forms, with or without modification,
17+
are permitted provided that the following conditions are met:
18+
19+
- Redistributions of source code must retain the above copyright notice, this list of
20+
conditions and the following disclaimer.
21+
- Redistributions in binary form must reproduce the above copyright notice, this list of
22+
conditions and the following disclaimer in the documentation and/or other materials
23+
provided with the distribution.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
26+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28+
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
32+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
35+
---
36+
37+
I have also chosen to dual-license under the Boost Software License as an alternative to
38+
the Simplified BSD license above:
39+
40+
Boost Software License - Version 1.0 - August 17th, 2003
41+
42+
Permission is hereby granted, free of charge, to any person or organization
43+
obtaining a copy of the software and accompanying documentation covered by
44+
this license (the "Software") to use, reproduce, display, distribute,
45+
execute, and transmit the Software, and to prepare derivative works of the
46+
Software, and to permit third-parties to whom the Software is furnished to
47+
do so, all subject to the following:
48+
49+
The copyright notices in the Software and this entire statement, including
50+
the above license grant, this restriction and the following disclaimer,
51+
must be included in all copies of the Software, in whole or in part, and
52+
all derivative works of the Software, unless such copies or derivative
53+
works are solely in the form of machine-executable object code generated by
54+
a source language processor.
55+
56+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
59+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
60+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
61+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
62+
DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)