1. Methods of multithreading synchronization
A) entercirticalsection leaveciriticalsection
b) Mutex mutex object WaitForSingleObject ReleaseMutex use method and the above one similar
c) CreateEvent WaitForSingleObject SetEvent The event object into a trusted state resetevent the event object to become untrusted, and through these two settings to control the execution of the thread waiting for the event object
d) Semophore and the above several single entry control is different, Semophore is to control multiple parallel portals, when these multiple entrances are occupied, Semophore objects become blocked state, So once the thread has finished working on the related tasks, remember to call Releasesemophore to release the resources
e) Waitformultiobject waits for more than one kernel object, and only these multiple kernel objects become trusted, and subsequent code can be executed.
2. About thread-local storage
Each thread has its own array, with a maximum length of 1000
Each time TlsAlloc finds an available index and then returns, then each thread in the process can call TlsGetValue or TlsSetValue with this index parameter to read and write the array elements of the corresponding index. Although threads can have the same index as arguments, this does not conflict because they all manipulate only the array associated with this thread
You can set the value of an array item of a specific index in the respective array without the index TlsSetValue provided by TlsAlloc
Windows Programming Learning