views:

72

answers:

1

I am reviewing code which creates a lot of threads. CreateThread documentation on Windows says that a all thread creation calls are serialized within a process. To estimate the performance impact of such code, I wonder how long does CreateThread take to run? I understand this depends on the number of DLLs already loaded into the process, but would like to know a ballpark value.

Thanks!

+1  A: 

Your best bet may be to write a unit test and see how long it takes for your application.

But, if you need a large number of threads, then while your program is starting up, in the initialization, you could spawn a thread that just starts to fill in an array of threads, so you can finish setting up your application and the threads will be ready when they are needed.

If I give numbers from my laptop, it will differ based on OS, processor, ram and perhaps .net version, so the numbers will be very rough at best.

James Black
+1 for pointing out that the times will depend on lots of factors.
Stephen C
and most DLL's DLLMain would be called. God knows what are in these functions.
Sheng Jiang 蒋晟