Click here to Skip to main content
Licence CPOL
First Posted 17 Jan 2006
Views 17,720
Downloads 459
Bookmarked 15 times

Synchronizing Multiple Threads in the ThreadPool

By | 17 Jan 2006 | Article
An article on thread synchronization and usage of ThreadPool
Sample Image - PoolSynchronization.jpg

Introduction

This snippet demonstrates one way of synchronizing multiple user worker threads by means of ManualResetEvents. I came across the question wherein you might have a number of computational threads and each thread has a number of computational stages. The constraint was that none of the threads can proceed to the next stage 'n+1' unless all threads completed stage 'n'.

Background

ThreadPool is beneficial in cases when the threads are not highly CPU intensive and are not prioritized. By using the thread pool, you save valuable resources on the actual thread creation.

Using the Code

The project consists of three main objects:

  • The GUI frmSwitchBoard
  • The synchronizing object CPoolSynchronizer
  • The object CComputeItem containing compute functions 'func'

From the GUI, you can control how many compute threads you wish to place in the ThreadPool.

You might also find it useful how to interact with WinForm controls asynchronously. CComputeItems update the progress independently from each other by calling Invoke() on the control.

History

  • 17th January, 2006 - Initial version submitted

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Manassypov

Web Developer

Canada Canada

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 17 Jan 2006
Article Copyright 2006 by Manassypov
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid