People who are familiar with WIN32 programming must know that the process management method of WIN32 is very different from that of Linux. In UNIX, there is only the concept of process, but in WIN32 there is also the concept of "thread", so Linux and WIN32 are here What's the difference?
The process/thread in WIN32 is inherited from OS/2. In WIN32, "process" refers to a program, and "thread" is an execution "clue" in a "process". From a core point of view, the multi-process of WIN32 is not much different from that of Linux. The thread in WIN32 is equivalent to the Linux process and is an actual executing code. However, in WIN32, data segments are shared between threads in the same process. This is the biggest difference from the Linux process.
The following program shows how the next process of WIN32 starts a thread.
int g; DWORD WINAPI ChildProcess(LPVOID lpParameter){ int i; for ( i = 1; i <1000; i ++) { g++; printf( "This is Child Thread: %dn", g ); } ExitThread( 0 ); }; void main() { int threadID; int i; g = 0; CreateThread( NULL, 0, ChildProcess, NULL, 0, &threadID ); for ( i = 1; i <1000; i ++) { g++; printf( "This is Parent Thread: %dn", g ); } }
Under WIN32, the CreateThread function is used to create a thread. Unlike creating a process under Linux, the WIN32 thread does not start running from the creation point. Instead, CreateThread specifies a function, and the thread starts running from that function. This program is the same as the previous UNIX program, with two threads each printing 1000 pieces of information. threadID is the thread number of the child thread. In addition, the global variable g is shared by the child thread and the parent thread. This is the biggest difference from Linux. As you can see, the process/thread of WIN32 is more complicated than that of Linux. It is not difficult to implement a thread similar to WIN32 in Linux. As long as after forking, the child process calls the ThreadProc function and opens a shared data area for global variables. However, It is impossible to implement functions similar to fork under WIN32. Therefore, although the library functions provided by the C language compiler under WIN32 are already compatible with most Linux/UNIX library functions, fork still cannot be implemented.
For multi-tasking systems, sharing data areas is necessary, but it is also a problem that can easily cause confusion. Under WIN32, a programmer can easily forget that data between threads is shared. After a thread modifies a variable , but another thread modified it, causing program problems. However, under Linux, since variables are not originally shared, the programmer explicitly specifies the data to be shared, making the program clearer and safer.
As for the concept of "process" in WIN32, its meaning is "application", which is equivalent to exec under UNIX.