ronag
ronag

Reputation: 51255

Task Parallel Library - Blocking Operations?

How does the .NET Task Parallel Library handle tasks with blocking operations? In the C++ Concrt library you have the Context::Oversubscribe method, but I haven't found such a thing in the .NET library? Is the LongRunningTask option the corresponding way to handle blocking tasks?

.i.e: in C++ you would do:

auto my_task_func = []
{
     //Do work...
     Context::Oversubscribe(true);
     // Short or long blocking op.
     Context::Oversubscribe(false);
     //Do more work.

}

Upvotes: 3

Views: 428

Answers (1)

usr
usr

Reputation: 171178

The TPL uses a hill-climbing algorithm to find the optimal number of threads without cooperation from the tasks themselves. It just keeps injecting threads until the task completion rate does not improve further.

Upvotes: 3

Related Questions