I'm looking at modifying a toy OS system and I'm just trying to learn some of the code and what it does. I have been given a "Thread" structure which has as a member a "pcb" structure, which is a process control block that interfaces the thread to the underlying physical hardware I guess.
Anyways, in this "pcb" structure there's the initialization function which initializes the pcb of a newly created thread. Here's the function definition:
void md_initpcb(struct pcb *, char *stack, void *data1, unsigned long data2,
void (*func)(void *, unsigned long));
With regards to the code, what is the meaning of the last argument? Does it relate to the code or instructions
Conceptually, I'm confused about how stuff fits into the bigger picture. From what I know, a Thread is a unit of execution of code; for example it can relate to user programs, so switching between threads rapidly gives the illusion of running processes in parallel. Alright so this Thread then needs its own stack, registers (don't understand), and some control (the pcb).
Sorry if this is kind of all over the place. For reference, I'm starting the OS161 project.
Thanks.
It's a function pointer. You pass it the address of a function that returns void and takes a void pointer and an unsigned long.
So, for example, if you have a function:
void myfunc(void *data, unsigned long number);
Then you could pass it as the fourth argument to md_initpcb
.
This function is the code that the thread you're creating is going to execute. When it finishes, the thread will finish too.