

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of creating threads in win32, including the use of dynamic link libraries (dlls), functions like _beginthread(), _endthread(), createthread(), and thread procedures. Additionally, it covers synchronization techniques such as critical sections, mutexes, and events to prevent conflicts when accessing shared resources.
Typology: Slides
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















CreateThread()
enum Shape { RECTANGLE, ELLIPSE };
DWORD WINAPI drawThread(LPVOID shape);
SYSTEMTIME st;
HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD DWORD dwStackSize, // initial stack size LPTHREAD_START_ROUTINE lpStartAddress, // thread function LPVOID lpParameter, // thread argument DWORD dwCreationFlags, // creation option LPDWORD lpThreadId // thread identifier
);
Threads example
hThread1 = CreateThread(NULL, 0, drawThread, (LPVOID)RECTANGLE, CREATE_SUSPENDED, &dwThread1); hThread2 = CreateThread(NULL, 0, drawThread, (LPVOID)ELLIPSE, CREATE_SUSPENDED, &dwThread2);
hDC = GetDC(hWnd);
hBrushRectangle=CreateSolidBrush(RGB(170,220,160));
hBrushEllipse = CreateHatchBrush(HS_BDIAGONAL,RGB(175,180,225));
InitializeCriticalSection(&cs);
srand( (unsigned)time(NULL) ); ResumeThread(hThread2); ResumeThread(hThread1);
HANDLE CreateMutex(
LPSECURITY_ATTRIBUTES lpMutexAttributes, // SD
BOOL bInitialOwner, // initial owner
LPCTSTR lpName // object name
);
DWORD WaitForSingleObject(
HANDLE hHandle, // handle to object
DWORD dwMilliseconds // time-out interval
Threads example with Mutex
Threads example
DWORD WaitForMultipleObjects(
DWORD nCount, // number of handles in array
CONST HANDLE *lpHandles, // object-handle array
BOOL fWaitAll, // wait option
DWORD dwMilliseconds // time-out interval
);
HANDLE CreateSemaphore(
LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, // SD
LONG lInitialCount, // initial count
LONG lMaximumCount, // maximum count
LPCTSTR lpName // object name
);