Windows multi thread technology basic knowledge

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

1, Process refers to an application is running in the system, is the unit of allocation of resources and scheduling operation units.

In 32 windows, occupy the 4GB of the virtual address space of a process.

In addition to the address space, the process also share some resources, such as files, dynamic memory allocation and thread, when the process terminates, all kinds of resource is created in the life will be removed, so that the process is not active.

2, Process is a task, the thread is independent sub tasks, can be made of different processor respectively to complete the process, improve the operating speed.

The thread is executing the way code plus a group operating system resource distribution (stack register state, etc.).

Each thread has its own a set of CPU registers and stacks, a process has at least one thread in the execution of the code in the address space.

The operating system provides time slice to thread in a round robin manner.

3, Thread at any time under the state is defined in the process of a block of memory and a CPU register, and the call stack storage variables and applications can be other threads that share memory.

4, The use of multi thread programming can:

(1)In response to improve application. (2) to make the system more effective than CPU. (3) to improve the program structure.

(4)Needs fewer system resources. (5) improved performance.

5, The system process the most basic:

smss.exe: The session manager process

csrss.exe: Subsystem server process,

winlogon.exe: User login management process

services.exe: Contains a lot of service process

lsass.exe: As a system service

svchost.exe: Contains a lot of service process. (for those who run from a DLL service is a regular host process name)

spoolsv.exe: As a system service, the file is loaded into memory in order to delay the print

6, Basic user process:

explorer.exe: The resource manager

internat.exe: Tray icon of Pinyin

7, System process additional:

mstask.exe: As a system service, allows the program to run at a designated time

regsvc.exe: As a system service, allows the program registry operation

winmgmt.exe: As a system service, to provide management information system

You can enter the list of TList -s showed an activity process in under the command of CMD.

8, The Performance tab in the task manager is CPU time percentage is thread in the process of occupation.

32 bit operating system most are based on a timing mechanism of interval.

9, Pseudo hidden refers to remain processes, just let it hours in the list of processes.

(as long as the Trojan server application to register as a service on the line. )

True hidden is let the program completely disappeared, do not work to a process or service mode. That is to say completely melt into the kernel.

10, The mutex object

The state of the Mutex object only signal in it is not used by any thread owns, and when it was thread has when no signal.

The Mutex object is quite suitable for the coordination of multiple threads to access shared resources.

(1)A mutex object, get handle:

HANDLE CreateMuetx( );

(2)The thread might conflict areas (i.e. prior access to a shared resource) called WaitForSingleObject, will handle passed to the function request, occupy the mutex object:

dwWaitResult = WaitForSingleObiect( hMutex, 5000L);

(3)The shared resource access end, freeing the mutex object:

ReleaseMutex( hMutex);

The mutex object at the same time can only be a thread take up, when the mutex object is a thread take up, if there is another thread to occupy it, you must wait until a thread releases to success.

11, At the same time signal objects allow multiple threads to access shared resources, specifies the maximum number of threads that can be accessed at the same time when the object is created.

When a thread for access to success, counter signal in the object of minus 1, call the ReleaseSemaphore function, plus 1 counter signal in the object. The counter value is greater than or equal to 0, but less than or equal to the maximum specified when creating thevalue.

If an application to create a semaphore object when the counter is set to 0, the initial value the other thread is blocked, the protection of resources.

Resource initialization is complete, call the ReleaseSemaphore function to counter increased to a maximum of value, can carry out normal access.

(1)Create a semaphore object:

HANDLE CreateSemaphore( );

Or open a semaphore object:

HANDLE OpenSemaphore( );

(2)Access to shared resources before calling WaitForSingleObiect on a thread.

(3)Shared resource access is completed, should release the occupation of the signal of object:

ReleaseSemaphore( );

12, The event object is the synchronization object is simple, which comprises a signal and no signal of two states.

Before accessing a resource in the thread, need to wait for an event, the event object is most appropriate.

For example: only in the communication port buffer to receive data, monitor the thread being active.

The event object is created by the CreateEvent function.

The initial state of the function can be specified event object classes and events.

If it is a manual reset event, so it always maintain a signal state, until the ResetEvent function is reset to no signal event.

If the automatic reset events, then its state in a single waiting thread after releasing will automatically become the no signal.

SetEvent can be used to put the event object set to signaled state.

In the establishment of the event, for the naming of object, handle to the event object so that other threads in the process you can open the specified name using the OpenEvent function.

13, The exclusion zone object

In the exclusion zone in the asynchronous execution, it can only share resources processing between the same process thread.

(1)To define a CRITICAL_SECTION structure zone of exclusion object when in use, in the process of use before invoking the following function to initialize the object:

VOID InitializeCriticalSection( LPCRITICAL_SECTION );

(2)When a thread uses the exclusion zone, the function call EnterCriticalSection or TryEnterCriticalSection.

(3)When asked to occupy, exit the exclusion zone, the function call LeaveCritialSetion release occupation of the rejection region of the object, for other threads.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Norman at December 12, 2013 - 1:56 PM