[Thread Objects & Thread]
Threads from concept is a thread that is executed, in principle, any program code segment can be
A thread, but the thread model of different operating systems is different, some systems use threads as used
Households to handle, real scheduling and resource allocation units are processes, while others use threads as basic
Scheduling and resource allocation unit. Specific in Windows OS, its thread model is made up of a function
The entrance pointer and an inlet parameter are determined, which can generally speak: in Windows (95 or more) systems
The process is a function running. The prototype life of this function is as follows: DWORD WINAPI THREADFUNCTION (LPVOID); there are two ways to create threads: one is to use the API function CreateThread, the other is to use
Line library function _BeginThreadex (declared in Process.h). The parameters and effects of the two are the same.
It is an address, entry parameter to return a pointer, stack size, and security for returning thread ID.
Attributes (two of them are generally not specially available). Let's take a look at how the thread object is abstract thread. First, there is a global function with thread objects: DWORD WINAPI DORUNWORKING (LPVOID LPPARM); this global function will be used to create a real thread. Then, starting from the constructor of the thread object, in addition to the necessary preparations, the main work is
Create a thread, use DORUNWORKING as a function address, create threads with the object's THIS pointer,
And the initial state of the thread is CREATE_SUSPENDED (hang) that is, the thread is not created.
Run immediately, until the call Run (it uses ResumeTHRead this API from the new start thread) this
The member function began to run the thread. Now, look at what action running to the thread: ThreadObject * p = (threadObject *) LPPARM; if (p) p-> working (); you can see that it gets the thread object from LPPARAM, then call member functions Working, this,
The execution control of threads is turning back to the hand of thread objects, and the DORUNWORKING is just from
A bridge role. Finally, end the thread in the sectors in the object. At this point, you can see that the thread object is abstracted from threads, and from the object creation start thread being created,
Start the thread with the RUN function, when the object is not survive, the thread is automatically terminated. Thread to do
When actually working in the Working this function.