1. Compared to threads, processes use more system resources. The reason for this is the address space. Creating a virtual address space for a process requires a lot of system resources. Threads have only one kernel object and one stack.
2. Entry functions for threads
DWORD WINAPI ThreadFunc (PVOID pvparam) {DWORD dwresult = 0;...return (dwresult);}
Several descriptions of thread functions
- Thread functions can be arbitrarily named.
- A thread function has only one parameter, and its meaning is defined by us (not the operating system). Therefore, we do not have to worry about ansi/unicode problems.
- A thread function must return a value that becomes the exit code for that thread.
- Thread functions should use function arguments and local variables whenever possible. The parameters and local variables of the function are created on the thread stack.
3.CreateThread function
HANDLE CreateThread (psecurity_attributes psa,dword cbstacksize,pthread_start_routine pfnstartaddr,pvoid PvParam, DWORD Dwcreateflags,pdword Pdwthreadid);
Calling the CreateThread function, the system allocates memory from the process's address space to the thread stack for use. The new thread runs in the same process context as the thread responsible for creating it. Therefore, the new thread can access all the handles of the process kernel object, all the memory in the process, and the stack of all the other threads in the same process .
Windows core Programming Reading notes-sixth chapter Threading Basics