Using Thread.Join to Ensure a Worker Thread Has Exited
Using threads is difficult. A developers coding complexity increases dramatically. Issues such as reentrance, deadlock and race conditions are difficult to detect and avoid. Creating, using and ending threads all require careful implementation of managing thread lifetimes.
In this discussion, we look at one way a thread can synchronize itself with another thread waiting for it to complete. This technique can be used as part of an orderly shutdown of worker threads. The System.Threading.Thread class has an instance member called Join that can provide this type of functionality. Join provides several overloads. Using Join is not difficult. But, using it wisely is.
For the simple Join case, we can call the Join overload that takes no arguments. This call will block until the thread being joined to has ended. The call is simple, but dangerous. Consider when this joined thread never ends! The calling thread would then be hung and would not be able to continue until some other thread interrupted or aborted it. This special case is difficult to code and best avoided if possible.
Thankfully Join also provides overloads that require a timeout parameter. Their use is preferred. These overloads take either a millisecond or a TimeSpan timeout. They both return a bool that is true to indicated the joined thread has exited, false otherwise.
<-- Example 1 ------------------------------->
// The semantics here are:
// The current thread calling Join(), "joins" the myThread thread instance.
// myThread is the thread being joined to.
// The current thread is then blocked until the myThread's ThreadStart delegate target
// has returned control back to the CLR by exiting.
myThread.Join(); // blocks until myThread completes
// At this point, myThread has exited.
<-- Example 2 ------------------------------->
// Created on some managing thread
ManualResetEvent quit = new ManualResetEvent(false);
// ThreadProc is defined and used as the delegate target.
// Somehow, the ThreadProc has access to quit WaitHandle
Thread t = new Thread(new ThreadStart(ThreadProc));
// managing thread signals created thread it is time to quit
quit.Set();
// Assumes the created thread will monitor the quit WaitHandle to know when to quit.
// The amount of time until the thread quits is application dependent.
// Choose an appropriate timeout for the Join below when considering this.
// later the managing thread waits for the created thread to exit
if (!t.Join(2000)) {
// report aborting thread
t.Abort();
}
<-- Example 1 ------------------------------->
// The semantics here are:
// The current thread calling Join(), "joins" the myThread thread instance.
// myThread is the thread being joined to.
// The current thread is then blocked until the myThread's ThreadStart delegate target
// has returned control back to the CLR by exiting.
myThread.Join(); // blocks until myThread completes
// At this point, myThread has exited.
<-- Example 2 ------------------------------->
// Created on some managing thread
ManualResetEvent quit = new ManualResetEvent(false);
// ThreadProc is defined and used as the delegate target.
// Somehow, the ThreadProc has access to quit WaitHandle
Thread t = new Thread(new ThreadStart(ThreadProc));
// managing thread signals created thread it is time to quit
quit.Set();
// Assumes the created thread will monitor the quit WaitHandle to know when to quit.
// The amount of time until the thread quits is application dependent.
// Choose an appropriate timeout for the Join below when considering this.
// later the managing thread waits for the created thread to exit
if (!t.Join(2000)) {
// report aborting thread
t.Abort();
}

26 Comments:
Big News From The Healthcare Industry!!
+++++++++++Current Profile+++++++++++
Faceprint Global Solutions (FCPG)
Current Price $0.15
A company with hot new identity solution products
and licenses with over 40 current governmental and
non-governmental contracts in negotiations.
+++++++++++++++++++++++++++++++++
Is this an undiscovered gem priced to go higher!!
Please read the following Announcement in its Entirety and Consider the Possibilities�
Watch this One to Trade!
FCPG volume trading is beginning to surge with this landslide Announcement. The value of this
stock appears poised for growth! This one should not remain on the ground floor for long.
BREAKING NEWS!!
Faceprint Global Solutions (FCPG) is pleased to announce that its European partner, Keyvelop, has teamed up with IBM's Partner World Industry Networks to deliver customer software requirement solutions for the international healthcare industry.
With FGS owning the exclusive North American rights to distribute the worlds leading encryption and transmission software developed by Keyvelop, FGS is poised to capture large volumes of sales generated by customers currently using IBM's software in the healthcare and other industries.
With traceability and security now deemed a serious business priority, companies are increasingly focused on employing procedures and controls designed to ensure the authenticity, integrity and confidentiality of electronic records.
"This is a very positive move for FGS and for Keyvelop," said FGS CEO Pierre Cote. "We are very happy about the decision to go with IBM. This is a continuation of the progress made by everyone associated with FGS and its partners."
Buell Duncan, IBM's general manager of ISV & Developer Relations commented, "Collaborating with Keyvelop will ensure that we develop open solutions that are easy to maintain and cost effective for our customers in the healthcare and life sciences industry."
Among other things, this new software technology which is currently being used by a number of European healthcare companies, is used to send any file, regardless of format or size. Encryption keys, evidence of transmission integrity with fingerprint calculation, time-stamping of all actions and status record updating, pre-checking sender and receiver identities, validating file opening dates are part of Keyvelop features.
About FacePrint Global Solutions, Inc.
FGS operates a business, which develops and delivers a variety of technology solutions, including biometric software applications on smart cards and other support mediums (apometric solutions). FGS's products provide biometric solutions for identity authentication and a host of smart card- and biometrics-related hardware peripherals and software applications. Apometrix, FGS's wholly-owned subsidiary, combines on-card or in-chip multi-application management solutions with best-of-breed 'in-card matching' biometrics. Keyvelop's secure digital envelope solution and Apometrix's on-card biometrics work together to produce the winning combination in the fields of security, traceability and identity management. FGS is headquartered in Fresno, California.
Conclusion:
The examples above show the Awesome, Earning Potential of little known Companies That Explode onto Investor's Radar Screens. This stock will not be a Secret for long. Then You May Feel the Desire to Act Right Now! And Please Watch This One Trade!
GO FCPG!
All statements made are our express opinion only and should be treated as such. We may own, take position and sell any securities mentioned at any time. Any statements that express or involve discussions with respect to predictions, goals, expectations, beliefs, plans, projections, objectives, assumptions or future events or performance are not statements of historical fact and may be "forward looking statements." Forward looking statements are based on expectations, estimates and projections at the time the statements are made that involve a number of risks and uncertainties which could cause actual results or events to differ materially from those presently anticipated. This profile is in no way affiliated with the featured company. We were compensated one thousand dollars from third party (IR Marketing) to distribute this report. Forward looking statements in this action may be identified through the use of words such as: "projects", "foresee", "expects". in compliance with Section 17(b), we disclose the holding of FGS shares prior to the publication of this report. Be aware of an inherent conflict of interest resulting from such holdings due to our intent to profit from the liquidation of these shares. Shares may be sold at any time, even after positive statements have been made regarding the above company. Since we own shares, there is an inherent conflict of interest in our statements and opinions. Readers of this publication are cautioned not to place undue reliance on forward-looking statements, which are based on certain assumptions and expectations involving various risks and uncertainties that could cause results to differ materially from those set forth in the forward- looking statements. This is not solicitation to buy or sell stocks, this text is for informational purpose only and you should seek professional advice from registered financial advisor before you do anything related with buying or selling stocks, penny stocks are very high risk and you can lose your entire investment.
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results chicago, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results free web design, maybe give us a call at 404-303-7350
I read over your blog, and i found it inquisitive, you may find My Blog interesting. My blog is just about my day to day life, as a park ranger. So please Click Here To Read My Blog
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results montreal, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results london, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results web site design, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results toronto, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results atlanta, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results san diego, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results atlanta, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results atlanta, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results wales, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results arizona, maybe give us a call at 404-303-7350
I read over your blog, and i found it inquisitive, you may find My Blog interesting. So please Click Here To Read My Blog
http://pennystockinvestment.blogspot.com
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results professional web design, maybe give us a call at 404-303-7350
Need A Great Web Site Jeff WS, Great post on Using Thread.Join to Ensure a Worker Thread Has Exited!, I have great site to offer the best prices on web design and get great results ecommerce web site design, maybe give us a call at 404-303-7350
Get any Desired College Degree, In less then 2 weeks.
Call this number now 24 hours a day 7 days a week (413) 208-3069
Get these Degrees NOW!!!
"BA", "BSc", "MA", "MSc", "MBA", "PHD",
Get everything within 2 weeks.
100% verifiable, this is a real deal
Act now you owe it to your future.
(413) 208-3069 call now 24 hours a day, 7 days a week.
hey, I just got a free $500.00 Gift Card. you can redeem yours at Abercrombie & Fitch All you have to do to get yours is Click Here to get a $500 free gift card for your backtoschool wardrobe
hey, I just got a free $500.00 Gift Card. you can redeem yours at Abercrombie & Fitch All you have to do to get yours is Click Here to get a $500 free gift card for your backtoschool wardrobe
You have shared here about thread that is created in c#.Tell me how we can create thread and edit.C# language is used for
website development or desing?
As soon as you set up your online business, you would definitely come across the challenge of surviving in a quickly growing competitive environment. Moreover, the ever-changing market trends would also pose challenges to you and at such a situation, efficient ecommerce solution may provide you the best business advantage that you can ever dream of. Come in touch with http://www.infyecommercesolution.com and avail of the best ecommerce solutions.
welcome to the wow power leveling cheap wow power leveling service site, buy cheap wow gold,wotlk gold,world of warcraft power leveling buy wow gold
Thanks, this article has helped me killing threads in my site that through threads calls multiple REST services simultaneously :)
Yimmiy, a search 2.0 site
Hi. This post is likeable and your blog is very interesting, congratulations!!
Regards,
retouching
We are sell wow gold and wow power leveling wow gold
Post a Comment
<< Home