Win32 Implementation

Now let’s take a look at the equivalent Windows implementation. The Windows implementation sits on top of the Win32 API. Win32 allows thread creation and execution to be a two-step process. So, let’s take advantage of that. That would imply that the entry function and parameter do not need to be in the struct. But the Win32 prototype for a thread entry function is somewhat different from MyOS, so we have to store the entry and parameter in the struct after all. Here is the struct:

src/MyOS/Win32/Thread.c
 
typedef​ ​struct​ ThreadStruct
 
{
 
HANDLE threadHandle;
 
ThreadEntryFunction entry;
 
void​ * parameter;
 
BOOL started;
 
} ThreadStruct;

Here is the Win32-compatible thread entry function:

src/MyOS/Win32/Thread.c ...

Get Test Driven Development for Embedded C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.