The sin of Suspend()

  • Thread starter Thread starter b.fokke
  • Start date Start date
B

b.fokke

Hi all!

I'm working on an application that due to the nature of the application
is heavily concurrent. Usually, there will be between 15 and 20 threads
running at the same time. However, at some times it might be necessary
to pause execution of these threads. Thread.Suspend() looks like an
excellent candidate, but the method is deprecated in the framework.
According to the documentation I should use dedicated objects like
Monitors for synchronization.

I do understand why using Suspend() for synchronization is a Bad Idea
(TM). But is it a bad idea for pausing (parts of) an application as
well? There is no way of telling which part of the code each thread is
executing and I would hate to have to litter my code with checkPaused()
methods, or something like that.

Does anyone know whether it is a sin to use Suspend() in this case and
why or why not?

Thanks in advance,
Bram Fokke
the Netherlands
 
As long as you are absolutely sure that one thread does not eat the same
piece of memory as another thread, both in managed code and below the
surface, suspend is not that wicked. It is deprecated largely because most
people only examined the surface and ignored what was going on below the
surface.

If you go this route, note that your code is not considered thread safe.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
I'm working on an application that due to the nature of the application
is heavily concurrent. Usually, there will be between 15 and 20 threads
running at the same time. However, at some times it might be necessary
to pause execution of these threads. Thread.Suspend() looks like an
excellent candidate, but the method is deprecated in the framework.
According to the documentation I should use dedicated objects like
Monitors for synchronization.

I do understand why using Suspend() for synchronization is a Bad Idea
(TM). But is it a bad idea for pausing (parts of) an application as
well? There is no way of telling which part of the code each thread is
executing and I would hate to have to litter my code with checkPaused()
methods, or something like that.

Does anyone know whether it is a sin to use Suspend() in this case and
why or why not?

If there is no way to tell where each of the threads are, it sounds
like a really bad idea to call Suspend. What if one of the threads owns
a lock which the other threads need? What if they're half way through
modifying some shared data, leaving it in an inconsistent state?

Is there really no point in your code which is executed sufficiently
regularly that it would make a good point to check for pausing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top