Labels

Monday, June 15, 2009

Threading || Suspend & Resume

Scope of Work


·          Suspend & Resume

 

 

Suspend & Resume:

 

Suspend -> SuspendRequested -> Suspend State

 

  • A thread can be explicitly suspended and resumed via the methods
    • Thread.Suspend and
    • Thread.Resume

 

  • A thread can suspend itself or another thread, even when the thread is blocked [WaitSleepJoin State].
  • A thread can be resumed only by another thread.

 

  • Resume will work only on a suspended thread, and not on a blocked thread.
  • Calling Suspend results in the thread briefly entering the SuspendRequested state, then upon reaching a point safe for garbage collection, it enters the Suspended state.

 

  • From .NET 2.0, Suspend and Resume have been deprecated, their use discouraged because of the danger inherent in arbitrarily suspending another thread. If a thread holding a lock on a critical resource is suspended, the whole application (or computer) can deadlock. This is far more dangerous than calling Abort – which would result in any such locks being released – at least theoretically – by virtue of code in finally blocks.

 

 

 

Notes :-

 

  • When an application is launched, memory and any other resource for that application are allocated. The Physical Separation of this memory and resources is called a Process. In general, it is impossible for standard processes to access each other's data without using a proxy. Using a proxy incurs major overheads and coding can be complex.
  • When Microsoft designed the .NET Framework, it added one more layer of isolation called an application domain or AppDomain. This application domain is not a physical isolation as a process is; it is a further Logical isolation within the process. Since more than one application domain can exist within a single process, we receive some major advantages.
  • Microsoft encapsulated all of the functionality for these application domains into a class called System.AppDomain.

 

  • In general, it is impossible for standard processes to access each other's data without using a Proxy. Using a proxy incurs major overheads and coding can be complex. However, with the introduction of the application domain concept, we can now launch several applications within the same process. Threads can easily execute across application domains without the overhead associated with inter-process communication. Another benefit of these additional in-process boundaries is that they provide type checking of the data they contain.

 

 

  • There is a great benefit to multi-threading your applications if the computer has more than one processor.
  • The operating system is responsible for determining which threads are executed on which processor. However, the .NET platform does provide the ability to control which CPU a process uses if the programmer so chooses. This is made possible with the  ProcessorAffinity property of the Process class in the System. Diagnostics namespace.

 

 

Hope this is clear now.

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

No comments:

Post a Comment