user156144
user156144

Reputation: 2295

Windows .net thread - can it starve for a long time?

Is it possible in .net for a thread to be blocked for a long time like over 10 seconds? Or does .net or Windows switch between threads to make sure they get executed?

Upvotes: 1

Views: 84

Answers (1)

Eric
Eric

Reputation: 11662

A thread can be blocked for a long time if it invokes a blocking operation, for example waiting for an event to fire:

  evt.WaitOne();

or trying to access a critical section:

  lock( _myLockObject )
  {
     // ...
  }

In these cases, your thread has ceded control, and the processor is devoted to letting other threads run.

But maybe you are asking whether a thread can just be starved out? Under all normal circumstances, the answer is 'no' -- the operating system ensures that all threads get a slice of the processor. There might be an exception if a very high priority thread is churning through cycles, but even then the operating system should not completely starve other threads.

If you see a thread that is not making progress over long intervals (like 10 seconds) then something else is probably wrong. It could be performing an operation that implicitly blocks (or maybe even is deadlocked) or it might never have actually started after being created.

Upvotes: 2

Related Questions