vineri, 13 noiembrie 2009

[C#] Threading

Where they are used
- Windows Forms applications use event-loop threads to handle user interface events. Separate forms execute on separate threads, so if you need to communicate between Windows Forms, you need to communicate between threads.
- ASP.NET pages execute inside the multi-threaded environment of IIS.
Multitasking refers to an operating system's ability to run more than one application at a time.
Cooperative multitasking - applications decide when leave the control to the system
Pre-emptive multitasking - An application is allowed to execute for a short period before it is involuntarily interrupted by the operating system and another application is allowed to execute
Process - The physical separation of this memory and resources
Primary or main thread - initial thread (c#: Main () method - Application.Run() )
-> A process has data and threads.
-> The thread is a pointer into the instruction stream portion of a process
Time slice or a quantum - The period that the process can execute
Free threading - The concept of spawning new threads within the same process
Apartment threading- each process was granted its own copy of the global data needed to execute

Process.ProcessorAffinity - ability to control which CPU a process uses

Thread Local Storage (TLS) -contains the registers, stack pointers, scheduling information, address spaces in memory, and information about other resources in use.
An interrupt is a mechanism that causes the normally sequential execution of CPU instructions to branch elsewhere in the computer memory without the knowledge of the execution program.

When a thread voluntarily takes itself out of the execution queue for a period, it is said to sleep.
Windows prioritizes threads on a scale of 0 to 31, with larger numbers meaning higher priorities:
-> A priority of 0 can only be set by the system and means the thread is idle
-> Priorities between 1 and 15 can be set by users of a Windows system
-> Threads running in a priority between 16 and 31 are considered to be running real-time
-> 16 - Real Time idle
-> 5-9 normal background

pview - monitor/set thread priorities

- .NET Framework added one more layer of isolation called an application domain
- it is logical isolation within the process
- we can now launch several applications within the same process.
- Any time that an assembly is loaded in an application, it is loaded into an AppDomain
- A process can have multiple App domain

Niciun comentariu:

Trimiteți un comentariu