Multithreading: final thoughts on the thread pool

Now that we’ve ended our study of the thread pool, you know that we’ve got two ways of spanning new threads for performing work in parallel: we can manage the thread lifetime by using the Thread class directly or we can rely on thread pool for managing threads for us. Since there are options, you might be wondering which option you should choose for your code.

Once more, there’s really no definitive answer: it all depends on your scenario. If I had to give an answer to that, I’d say that most of the time you’d be better using the thread pool instead of creating your own threads. There are, however, a couple of scenarios where you should create your threads explicitly. For instance:

  • if you need to set the apartment type;
  • if you need to set the type of thread (pool threads are always background threads);
  • if the application will take a long time to end.

Btw, there are also some scenarios where you should be careful in relying on the thread pool. For instance, in ASP.NET apps, you shouldn’t forget that ASP.NET will also use it for its own work (everything should go well if you’re just queuing small tasks: just don’t get too greedy and start queuing work on the thread pool:),,)

For those that are worried with performance, I guess that using the pool will improve it for many scenarios (specially if we’re talking about parallelizing small tasks) because you’re amortizing the thread creation by using the same threads several times for different tasks.

The new .NET 4.0 thread pool introduces several new features which you can reuse when using the parallel library. This is really cool stuff and I’ll redirect you to Daniel Moth’s excellent blog for getting more details on this new feature.

And that’s it for now. In the next posts, we’ll keep looking at multithreaded

Advertisements

~ by Luis Abreu on June 5, 2009.

15 Responses to “Multithreading: final thoughts on the thread pool”

  1. Luis,

    I have not had a chance to look at the .NET 4.0 stuff yet, but have they introduced a wrapper around the ThreadPool that would let you process tasks using a predefined amount of threads? There are a lot of times you want to process a task in the thread pool, but you want to constrain the amount of threads that are being used to process a given task. This is a pretty common scenario that you can do yourself, but it seems like something that should ship in the framework — ala Java”s Executors and ExecutorService.

  2. Eric, I still didn”t have the time to take a deep look at the 4.0 version. Daniel Moth has some info on this stuff, but I haven”t looked at it yet…

  3. Around the: Strapon, Shemale strapon, Strapon f to m, Lesbian strapon video http://femdom.goodnano-av.com/

  4. ead more hot reports about Loan, First horizon home loan or Veterans small business loan http://finance.goodnano-av.com/

  5. Now I explain you all detail about Florida, Florida republicans, Colonic florida, and Copywriter florida http://florida.goodnano-av.com/

  6. Top finance experts said: Free, Free picture gallerys, Free game online tetris, My credit score for free http://free.goodnano-av.com/

  7. thanks

  8. Hi everyone

    Sorry to be off topic but I coudn”t resist sharing this, hoping it might help some of you.
    I am not really new to this forum but never bothered to write anything until now. I have reading around this and that forum to find some solution to my problems. I don”t want to bore you guys with my horror story but I would like to say a few words to encourage others.

    I use to get panic attacks since my childhood and now I am 26. I was some how living with it due to support from my father and friend. I am shy by nature and find it hard to mix with people and so I have few friends. But around 5 years ago, things turned to worst. I lost my parents in an accident. I then my life was turned upside down. I some how managed to get a boyfriend and I finally felt like coming back to life. I loved her and he too but I guess, I was making his life miserable and so he left, 6 months ago. Ok enough of my sad life.

    I actually never lost faith in myself. I was taking medication and I spent quite a lot of time on internet looking for some miracle information. I bought lot of books, CDs and what not. And then, I stumbled upon this course by Mr. Sal. It”s called Panic away. Just search for “panicaway dot com” and u will find it. I also tried the famous linden method but former seems to work better for me.

    And since then my life is slowly and slowly turning around.
    His approach is simple and yet effective. I started reading it around 4 months ago and the last attack that I got was 41 days ago. Earlier, it used to be like 1-2 times each week.I wish that I had found this course an year ago. Anyway. That”s it, I would say that you guys so give it a try and if this helps you then my effort of writing this looong post would be worthwhile.

    I am now looking forward to a life without fears. Wish me good luck.
    [img]http://trend-fusion.com/pics/smiley4.gif[/img]
    [img]http://trend-fusion.com/pics/smiley7.gif[/img]

  9. I just accidentally found this TV site hehe. http://creamytv.com/

    This site is just awesome! every streaming video is free and they uploaded at least 5 different source for each TV episode so we can still see even if one source is broken. I just watched 2012 and New Moon full streaming video~ high quality video, I love them. This site also have Asian movie like korean, japanese, chinese like that wow! recommended. score 100 out of 100!

  10. In the blossoming world of cosmetic dentistry, teeth whitening reigns supreme. Universally valued by men and women alike, whitening (or bleaching) treatments are available to satisfy every budget, time frame and temperament.

    Whether in the form of one-hour bleaching sessions at your dentist”s office, or home-use bleaching kits purchased at your local drugstore, teeth whitening solutions abound. Yet only 15 percent of the population has tried the cosmetic procedure, and misinformation on the subject is rife.

    The long and the short of it is that teeth whitening works. Virtually everyone who opts for this cosmetic treatment will see moderate to substantial improvement in the brightness and whiteness of their smile. However, teeth whitening is not a permanent solution and requires maintenance or “touch-ups” for a prolonged effect.

    British Columbia Zoom Teeth Whitening
    Teeth Whitening Del Mar
    Kansas City Teeth Whitening
    New York Teeth Bleaching
    Teeth Whitening La Jolla
    Newport Beach Teeth Whitening
    Overland Park Teeth Whitening
    Teeth Whitening Los Angeles
    Yorba Linda Teeth Whitening
    Teeth Whitening Newport Beach
    Teeth Whitening Gift Certificates
    Mt Laurel Teeth Whitening
    Teeth Whitening Pacific Beach
    New Canaan Teeth Whitening
    Medford Or Teeth Whitening
    Los Angeles Whiten Teeth
    Morris County Teeth Whitening
    Teeth Whitening Salt Lake City
    Teeth Whitening Beverly Hills
    Teeth Whitening Tv Advertisements
    Farmington Hills Teeth Whitening
    Teeth Whitening At Home
    Hillsboro Beach Teeth Whitening
    Westport Zoom Teeth Whitening
    Salt Lake City Teeth Whitening
    Kansas City Zoom Teeth Whitening
    Newport News Teeth Whitening
    Natural Way To Whiten Teeth
    Does Hydrogen Peroxide Whiten Teeth
    Orange County Teeth Whitening
    Ann Arbor Teeth Whitening
    Phoenix Zoom Teeth Whitening
    Tempe Zoom Teeth Whitening
    New Canaan Zoom Teeth Whitening
    Best Teeth Whitening System
    Darien Zoom Teeth Whitening
    Perfect Teeth Los Angeles
    Mesa Zoom Teeth Whitening
    Rancho Santa Fe Teeth Whitening
    Overland Park Zoom Teeth Whitening
    Natural Ways To Whiten Teeth
    I Want A Natural Way To Whiten My Teeth
    Best Teeth Whitening Products
    Perfect Teeth Beverly Hills
    University Park Teeth Whitening
    Teeth Whitening Pleasant Hill
    Sugar Land Teeth Whitening
    Fairfield Zoom Teeth Whitening
    Average Cost Of Braces For Teeth
    Did George Washington Have Wooden Teeth
    What Are Teeth Made Of
    All I Want For Christmas Is My Two Front Teeth
    La Jolla Teeth Bleaching
    When Do Babies Get Teeth
    Dream About Teeth Falling Out Mean
    Pictures Of Teeth Decay
    St Louis Teeth Crown
    Overland Park Teeth Crown
    Salt Lake City Teeth Crown
    San Ramon Teeth Crown
    Teeth Whitening Newsletters
    Home Remedies For Whitening Teeth
    Fake Real Looking Teeth
    Washington Dc Wisdom Teeth
    White Spots On Teeth
    How To Brush Your Teeth
    Dangers In Whitening Teeth
    Diagram Of Human Teeth
    Gobbo X Golden Teeth Pron
    Teeth Whitening Countertop Displays
    Straighten Teeth Without Braces
    Does Pallet Expander Cause Gap In Teeth

  11. Louisville Kentucky is a self-denial developing cosmopolitan diocese in the Communal States of America. The diocese was established in 1778 on George Rodgers Clark. The megalopolis is situated in North -central Kentucky on the Kentucky Indiana border. The city stands in mid the safest cities in the In harmony States with a totality populace of 1,268,323 as at 2008. This is the 42nd most populated bishopric in the Agreed States of America.

    Louisville Kentucky see is controlled by both the Metro mayor and a legislative body called Metro Council. The Metro Council comprises of 26 seats which get ahead in the world from the 26 Districts constituting the Louisville Kentucky metropolitan area. The caucus is directed nigh the caucus president with 13 seats being reelected after each two years of civil office.

    Louisville Kentucky is the occupation to deify in if you are looking in the interest of an unmatched investment arena in the Coordinated States of America. The thriftiness of this burg is radically improved with shipping and carload industries being the first-rate developed. Louisville Kentucky is centrally situated in the US and features greater road networks and highways linking celebrated cities across the US. It is also assisted past a well developed iron horse modus operandi that is excellent because of shipload and passenger traffic. Better silently, Louisville is nursing home to the Louisville Oecumenical Airport which is a intercontinental bearing hub with modern shipment handling capabilities.

    Louisville Kentucky is the hottest destination of churches assuring your weekends momentous and utmost of fun. The burgh is served not later than a vibrant media with prominent intercontinental networks and newspaper coverage. Parks and alfresco attractions are within the city environs making it identical of must-go-before-I-die cities. Don’t stand by, scrutinize forward and peregrinations to Louisville Kentucky sooner than possibility thaws.
    Louisville Kentucky Churches

  12. Louisville Kentucky is a fast developing cosmopolitan city in the United States of America. The municipality was established in 1778 next to George Rodgers Clark. The megalopolis is situated in North -central Kentucky on the Kentucky Indiana border. The town stands in lot the safest cities in the Synergistic States with a total population of 1,268,323 as at 2008. This is the 42nd most populated urban district in the Agreed States of America.

    Louisville Kentucky see is controlled on both the Metro mayor and a legislative essence called Metro Council. The Metro Council comprises of 26 seats which reach the top from the 26 Districts constituting the Louisville Kentucky metropolitan area. The congregation is directed about the caucus president with 13 seats being reelected after each two years of bureaucratic office.

    Louisville Kentucky is the place to deify in if you are looking as a remedy for an best investment arena in the Amalgamated States of America. The economy of this urban district is radically improved with shipping and wagon-load industries being the best developed. Louisville Kentucky is centrally situated in the US and features principal passage networks and highways linking celebrated cities across the US. It is also assisted next to a well developed rail modus operandi that is model looking for freight and passenger traffic. Improve silently, Louisville is conversant with to the Louisville Foreign Airport which is a cosmopolitan associated with heart with in vogue trainload handling capabilities.

    Louisville Kentucky is the hottest journey”s end of churches assuring your weekends memorable and utmost of fun. The city is served by a vibrant media with conspicuous worldwide networks and newspaper coverage. Parks and out of doors attractions are within the big apple environs making it one of must-go-before-I-die cities. Don’t stand by, make headway presumptuous and travel to Louisville Kentucky previous time thaws.
    Louisville Kentucky Business

  13. I have been looking at this site and find it to be really helpful. I would really appreciate any help.

  14. I have been looking at this site and have found it to be really helpful. I would greatly appreciate any assistance.

  15. I have been looking at this site and find it to be really helpful. I would greatly appreciate any assistance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: