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

[BUG] wait_for_tasks() Segmentation Faults in Conjunction with submit() #38

Closed
J-B-Blankenship opened this issue Mar 24, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@J-B-Blankenship
Copy link

Describe the bug

Extended usage of the thread_pool library causes odd quirks. Particularly, the call wait_for_tasks() crashes when paired with the submit() and storing into a std::vector of std::future(s). I have not been able to replicate beyond the fact it occurs in the same test. I have tried replicating the issue to no avail with similar calls. Unless an edge case has been missed in my unit tests (likely, but probably not), the call itself crashes as the function passes through without issue with similar parameter specifications.

Minimal working example

Short of giving you my source code for my project, there is not much. Submit some tasks with the std::future(s) stuffed into a std::vector. Call wait_for_tasks(). Then I have a section of code for accessing the values in the futures.

Behavior

Conjoined usage of the wait_for_tasks() and submit().

System information

  • CPU model, architecture, # of cores and threads: i7-10875H x 16
  • Operating system: Ubuntu 21.10
  • Name and version of C++ compiler: gcc 11.2
  • Full command used for compiling, including all compiler flags: Bazel's -c opt and C++20 specified
  • Thread pool library version: latest

(Please note that only the latest version of the thread pool library is supported.)

Additional information

I did some digging into the source code. There are a lot of C-Style casts amongst other bits and pieces that lead to undefined behavior. At one point, I went so far as to strip out everything but the code itself to see what was going on (lots of noise otherwise). No luck.

My best guess is either a cast is failing (unlikely, but maybe) or a race condition exists within the logic of the submit() and/or wait_for_tasks().

@J-B-Blankenship J-B-Blankenship added the bug Something isn't working label Mar 24, 2022
@J-B-Blankenship J-B-Blankenship changed the title [BUG] wait_for_tasks() Segmentation Faults in Conjunction with submit_task() [BUG] wait_for_tasks() Segmentation Faults in Conjunction with submit() Mar 24, 2022
@bshoshany
Copy link
Owner

Thanks for the bug report. Many people, including myself, are using this thread pool in a variety of complex scenarios, and have not encountered the issues you are describing. So unless you provide a minimal working example that reproduces this bug, there's nothing I can do.

Also, there's nothing wrong with C-style casts, their behavior is well-defined. I do agree that using C++ cast expressions is clearer, but I don't see why the C-style casts used in the library would lead to any bugs or ill-defined behavior.

@qwiff-dogg
Copy link

qwiff-dogg commented Sep 19, 2023

Just FYI.

My application was frequently (but now always) crashing with a Segmentation Fault, when wait_for_tasks was invoked on a separate thread. In this case, the thread was launched using std::async(std::launch::async, my_function)

Moving the wait_for_tasks invocation to the application's main thread solved the problem for me.

@bshoshany
Copy link
Owner

Thanks for letting me know. Mixing std::async with BS::thread_pool is not recommended; instead, consider using only BS::thread_pool, or perhaps two BS::thread_pools. If you are still having issues, please open a new issue with a minimal working example and I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants