Avatar of mcglinchey
mcglinchey

asked on 

Win NT ThreadPool

How much overhead is involved in creating a new thread in Windows NT?  If I have an application that will start up sessions, each of which will use a thread, is there any advantage in creating a ThreadPool object to pre-allocate and then dispense these threads?  Is it efficient enough just to create and destroy threads as needed?
C++

Avatar of undefined
Last Comment
nietod
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mcglinchey
mcglinchey

ASKER

In particular, I'm interested in knowing if the overhead is appreciable compared with the overhead of maintaining a thread pool; eg a thread pool will need to maintain a semaphore, and will keep more threads than necessary in idle state.

To be concrete: the session may last for 5 minutes (so a thread's life might average ~ 5 minutes). There may be say 30 threads in a pool, and that would be the maximum expected # of sessions.  Most of the time, though, 80% of those threads will be idle.

Do you have a feeling for if keeping the threads' resources around and idle is more costly than the cost of creating and destroying threads as they're needed?
Avatar of nietod
nietod

For thread lives of that sort of length, you will not see any measurable benefit to having a thread pool.  The thread's useful length is 3 or 4 order of magnitude more than the time needed to create the thread.  (remember the 80-20 rule.  Even if it was the 1--99 rule, a thread pool wouldn't help.)

Futhermore, with that many threads (30) you would almost certainly be better off not having the threads sitting around doing nothing.  There is some cost to having suspended threads (Idle thread threads are obviously costly, but suspended ones are too.) and the more threads, the more the cost.  Note also that NT seems to have no problem with so many threads in a process (although it will be costly) Windows 95 would almost certainly not do well with so many threads in a process (things tend to break down in the 7-10 thread vicinity.)  I don't know if that matters to you
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo