Comments (12)
Hey,
Thanks for notifying me. I had no idea someone performed tests on my thread pool and it failed. I actually never thought someone would use this. I did this project to learn how threads worked and never expected someone to use it in a professional environment. I did everything for learning purposes.
Nowadays, I am really busy with my current job but I keep this in mind and I'll try to fix it in the future.
Thanks,
Mariano.
from thread-pool.
Looks like there is deadlock which cause cpu to go 0 and app freezes.
from thread-pool.
Deadlock can occurs due to race/spurious wakeup.
from thread-pool.
It seems that it is missing the lockguard/unique_lock in two places:
m_conditional_lock.notify_all()
and
m_conditional_lock.notify_one()
from thread-pool.
It doesn't work that way. To protect against spurious wakeup, you should do something like this: https://github.com/yvoinov/thread-pool-cpp/blob/thread-pool-cpp-round-robin-stealing/include/thread_pool/worker.hpp. Mutexes do not play here. (If we're really have spurious wakeup case here.)
from thread-pool.
The code seems a bit complicated. What's spurious wakeup case, do you mind elaborating a little bit on it? https://stackoverflow.com/questions/17101922/do-i-have-to-acquire-lock-before-calling-condition-variable-notify-one
also:
https://thispointer.com/c11-multithreading-part-7-condition-variables-explained/
from thread-pool.
This about different thing. Of course, you always can make your own tests to prove your own theory :)
from thread-pool.
You can also refer to this example: https://github.com/vit-vit/ctpl, which is working, but a bit slower.
from thread-pool.
I can cite a bunch of links proving that there is no need to block the notification of conditional variables. But I will not. :) You can continue to stay with your own delusions. :) But I advise you to better examine the issue of spurious wakeup.
from thread-pool.
In addition: Mutexes is not slow. Slow only lock contention. So, think more, does you really want to slow down thread pool.
from thread-pool.
It looks to me the bug is in line 32: m_pool->m_conditional_lock.wait(lock); Here it needs to check certain condition is met or not to tell whether it is spurious wake up or not.
m_pool->m_conditional_lock.wait(lock, [this]{return ! m_pool->m_queue.empty();});
from thread-pool.
It looks to me the bug is in line 32: m_pool->m_conditional_lock.wait(lock); Here it needs to check certain condition is met or not to tell whether it is spurious wake up or not.
m_pool->m_conditional_lock.wait(lock, [this]{return ! m_pool->m_queue.empty();});
I think you right, you can set up cpu core to thread to avoid that, or trying to wait_for certain time
from thread-pool.
Related Issues (15)
- Is it redundant with two locks? HOT 2
- Synchronization on shutdown. HOT 5
- Is there a way to have a member method as the executed function? HOT 2
- the runtime is very slow when you have a lot of light functions HOT 2
- Building problem - cmake configure HOT 2
- Would you tell me why you use notify_one instead of notify_all here?
- How to wait for all tasks to finish?
- The output file doesn't output anything on compiling on Windows with MinGW-w64
- Not threadsafe
- 应用层,类的非静态函数不能使用,目前仅静态函数可用 HOT 3
- Bug report: When sub-task are performed quickly, the results are inaccurate HOT 4
- duplicated mutex? HOT 1
- How to use C++ member function in thread pool HOT 5
- Heap allocation issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thread-pool.