Lab 08
Lab 08
Windows API
Objective
Lab Requirements
Technical Requirements (software/ hardware).
Tools
Lab Assessment
Lab Assignment
Lab Description
Thread Management
CreateThread
The CreateThread system call creates an executable thread in the calling process's
address space.
Specify the stack size, and the stack space is allocated from the process's virtual
address space.
CreateThread returns a thread's ID value and its handle. A NULL handle value
indicates a failure.
dwStackSize is the byte size of the new thread's stack. Use 0 to default to the primary
thread's stack size.
lpStartAddr points to the function (within the calling process) to be executed. This
function accepts a single pointer argument and returns a 32-bit DWORD exit code. The
thread can interpret the argument as a DWORD or a pointer. The thread function
signature, then, is as follows:
lpThreadId points to a DWORD that receives the new thread's identifier. The pointer
can also be NULL, indicating that no thread ID will be returned.
Terminate Thread
All threads in a process can terminate themselves using the ExitThread function.
When the last thread in a process terminates, the process itself terminates.
One thread can terminate another thread with the TerminateThread function
Thread Identity
You can obtain thread IDs and handles using functions that are similar to those used
with processes.
One thread can increment or decrement the suspend count of another thread using
SuspendThread and ResumeThread. Recall that a thread can be created in the
suspended state with a count of 1.
CreateThread code
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <time.h>
Repeat the above two times and observe the order of execution of each thread
and comment.