<> Multithread related functions

Thread basic function :
// Create a thread , Returns a smart pointer to an unsigned type , Can be forced into HANDLE unsigned long _beginthread(StartAddress,
// Thread handler StackSize,// Application space size , set up 0 Is the default value ArgList// Thread handler parameter list );
// Create thread function , Added ex More powerful, of course , Default parameters CreateThread(NULL,0,ThreadFun,"hello",0) unsigned long
_beginthreadex(IpThreadAttributes,//NULL, Use default security dwStackSize,//0, The same size as the thread calling the function
IpStartAddress,// Thread handler , A function name is a function pointer IpParameter,// Parameters required by thread processing function dwCreationFlags,
//0, Do it now IpThreadId);// Return thread ID // Thread handler void Sell1(LPVOID ThreadParameter)
// Close thread handle function ( Just invalidate the handle , The thread did not end ), Close one ** kernel ** object BOOL CloseHandle(HANDLE hObject);
// Thread pending DWORD WINAPI SuspendThread(HANDLE hThread); // Resuming suspended threads DWORD WINAPI
ResumeThread(HANDLE hThread); // Gets the current thread ID GetCurrentThreadId() // Wait for a thread to finish executing
WaitForSingleObject(hThread,// Handle to thread object dwMilliseconds)// waiting time ,0-INFINETY
// Wait for multiple threads to finish executing WaitForMultipleObject(number_hThread,// The number of threads in the input array hThread,// Thread array
bool,// Do you want to wait for all threads to finish before returning dwMilliseconds)// waiting time ,0-INFINETY
<> Thread synchronization and mutual exclusion

There are several ways to implement user mode : Critical area ;
There are several ways to implement it in kernel mode : mutex , Semaphore , event ;( Only one process is available )

<> Critical region correlation function
CRITICAL_SECTION Section;// Critical zone statement InitializeCriticalSection(&Section);// Critical region initialization
EnterCriticalSection(&Section);// Enter critical zone LeaveCriticalSection(&Section);
// Leave the critical area , Code executed in the middle cannot be preempted bool TryEnterCriticalSection(&Section)// Try to enter the critical zone , Can make thread not be blocked
DeleteCriticalSection(&Section)// Delete critical area
unwanted WaitForSingleObject

<> mutex Mutex correlation function
HANDLE CreateMutex(SemaphoreAttributes,// Security properties , default NULL InitialOwner,
// Does the thread calling the mutex have permission to use it Name// The name of the semaphore ,NULL Represents an anonymous semaphore ) bool ReleaseMutex(hMutex)
WaitForSingleObject You can make the current thread get the exclusive usage right

<> Semaphore (Semaphore) correlation function
HANDLE CreateSemaphore(SemaphoreAttributes,// Security properties , default NULL InitialCount,// The initial value of the semaphore
MaxCount,// Maximum value of semaphore Name// The name of the semaphore ,NULL Represents an anonymous semaphore ) bool ReleaseSemaphore(hSemaphore,
// Semaphore handle ReleaseCount,// Number of released semaphores PreviousCount// Previous semaphores , Can be set to NULL)
WaitForSingleObject, If there is residual semaphore, it is used , If not, it will block

<> event (Event) correlation function

WIN32 Provides the most flexible way, the thread synchronization way ( Because you can set manual and automatic ?)
HANDLE CreateEvent(SemaphoreAttributes,// Security properties , default NULL bool ManualReset,// Manual or not
bool InitialState,// Initialize to signaled state Name// The name of the semaphore ,NULL Represents an anonymous semaphore )
// Created Event If it is manual, it should be set in the following way Event Signal status , If it's automatic, use it WaitForSingleObject bool SetEvent(
hEvent);// Set to signaled state bool ResetEvent(hEvent);// Set to no signal state

©2019-2020 Toolsou All rights reserved,
java Four functional interfaces ( a key , simple ) It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Browser kernel ( understand )HashMap Explain in detail Some East 14 Pay change 16 salary , Sincerity or routine ?html Writing about cherry trees , Writing about cherry trees