Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TaskCreationOptions.LongRunning option and ThreadPool

TPL uses Task Schedulers to coordinate tasks. According to official document, default task scheduler uses Thread Pool, but if TaskCreationOptions.LongRunning option is presented then it will create a dedicated thread for that task (A).

Question: As of now MSDN documents for Visual Studio 2010 are not ready and current online MSDN is not finalized; does anyone knows if (A) is true or false?

like image 728
Kaveh Shahbazian Avatar asked Jun 23 '10 22:06

Kaveh Shahbazian


2 Answers

Yes, LongRunning forces the creation of a new thread outside the pool. Here's some pseudo-disassembled code from the latest framework version:

...
if (task.Options HasFlag LongRunning) then
    create new Thread thread
    thread.Start(task)
...

Edit: converted from ugly C# to pseudocode.

like image 151
Mau Avatar answered Nov 07 '22 01:11

Mau


Presumably you can check this by using "Thread.IsThreadPoolThread":

http://msdn.microsoft.com/en-us/library/system.threading.thread.isthreadpoolthread.aspx

like image 15
Tim Lloyd Avatar answered Nov 07 '22 00:11

Tim Lloyd