I'm new to threads and boost, so I'm sure this is a real newbie question and hopefully quite easy to answer! I'm trying to set up a pool of threads that do a calculation, and I want to wait for those calculations to finish. Normally I'd do thread_group.join_all() to wait for the threads to exit - but in this case I want my threads hanging around so that I can redo that calculation over and over again when I ask it to do. What's the best way to signal back to the main thread that all calculations are complete? Should I use a barrier?
Threads share the process memory. Inter-thread communication via memory is the fastest. Synchronization may be required for memory access amongst producers and consumers. However, implementations exist that require no lock to avoid context switch for systems with critical demand on performancem ----- Original Message ----- From: Mark Higgins [mailto:miggins@gmail.com] Sent: Friday, September 16, 2011 12:50 AM To: boost-users@lists.boost.org <boost-users@lists.boost.org> Subject: [Boost-users] threads: shared lock question I'm new to threads and boost, so I'm sure this is a real newbie question and hopefully quite easy to answer! I'm trying to set up a pool of threads that do a calculation, and I want to wait for those calculations to finish. Normally I'd do thread_group.join_all() to wait for the threads to exit - but in this case I want my threads hanging around so that I can redo that calculation over and over again when I ask it to do. What's the best way to signal back to the main thread that all calculations are complete? Should I use a barrier? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users PLEASE READ: This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you receive this message in error, please delete it and all copies from your system, destroy any hard copies and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. Nomura Holding America Inc., Nomura Securities International, Inc, and their respective subsidiaries each reserve the right to monitor all e-mail communications through its networks. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorized to state the views of such entity. Unless otherwise stated, any pricing information in this message is indicative only, is subject to change and does not constitute an offer to deal at any price quoted. Any reference to the terms of executed transactions should be treated as preliminary only and subject to our formal written confirmation.
Hi Mark, You may use conditional variables in threads. Perform the calculation in each thread, acquire lock and then wait for conditional variable to be notified from the main thread. The above steps should be put into some loop. I use this technique in my analysis: loop example: http://goo.gl/mi6rr conditional variable use: http://goo.gl/8BVKv my condition class: http://goo.gl/sVS7y [separate repository] Good Luck, Samvel On Thu, Sep 15, 2011 at 11:50 PM, Mark Higgins <miggins@gmail.com> wrote:
I'm new to threads and boost, so I'm sure this is a real newbie question and hopefully quite easy to answer!
I'm trying to set up a pool of threads that do a calculation, and I want to wait for those calculations to finish. Normally I'd do thread_group.join_all() to wait for the threads to exit - but in this case I want my threads hanging around so that I can redo that calculation over and over again when I ask it to do.
What's the best way to signal back to the main thread that all calculations are complete? Should I use a barrier?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Mon, Sep 19, 2011 at 9:12 AM, Samvel Khalatyan <samvel.khalatyan@gmail.com> wrote:
Hi Mark, You may use conditional variables in threads. Perform the calculation in each thread, acquire lock and then wait for conditional variable to be notified from the main thread. The above steps should be put into some loop. I use this technique in my analysis: loop example: http://goo.gl/mi6rr conditional variable use: http://goo.gl/8BVKv my condition class: http://goo.gl/sVS7y [separate repository]
You need to be careful with condition variables, as they typically edge-triggered rather than level-triggered. If they are edge-triggered and the calculation completes and signals before anything is actually waiting on the CV then the waiter will not be signaled.
You need to be careful with condition variables, as they typically edge-triggered rather than level-triggered. If they are edge-triggered and the calculation completes and signals before anything is actually waiting on the CV then the waiter will not be signaled.
That's why CV should be used with a state variable.
participants (5)
-
Chris Cleeland
-
Igor R
-
jiryih.tsaur@nomura.com
-
Mark Higgins
-
Samvel Khalatyan