POSIX Implementation

To make this test pass for POSIX, we’ll have to use the POSIX pthread functions properly. The POSIX thread create function also starts the thread, so the MyOS Thread creation function can’t call pthread_create. It has to store the parameters, so when Thread_Start is called, it can create and start the thread. Here is the MyOS data structure used in the POSIX implementation:

src/MyOS/posix/Thread.c
 
typedef​ ​struct​ ThreadStruct
 
{
 
ThreadEntryFunction entry;
 
void​ * parameter;
 
pthread_t pthread;
 
} ThreadStruct;

pthread_t is an abstract data type (ADT) from the POSIX API. Here is the POSIX implementation of Thread_Create:

src/MyOS/posix/Thread.c
 
Thread Thread_Create(ThreadEntryFunction f, ​void​ * parameter)

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.