My Kernel v0.1.0

Worker thread.

Collaboration diagram for Worker thread:

Worker thread

A worker thread is a wrapper around a regular kernel thread, designed so that other threads can wait until it completes before continuing to execute.

It can be particularily useful in order to delay the execution of a costly function inside an interrupt handler. The kernel thread would be created and listed, but its execution would be delayed until interrupts are re-enabled (e.g. network packet RX codepath after copying it in memory).

Another usecase is to use it as as a synchronisation point between threads. An example for that can be seen in the network layer. When sending an IP packet to a destination never seen before, we first need to find what the destination's MAC address is. To do this we'd need to perform an ARP request, and wait until it completes before filling the Ethernet frame.

Using this API, this would look something like this:

static DECLARE_(arp_worker);

void send_ip_packet(packet) { fill_ip_header(packet);

if (!destination_seen) { worker_start(&arp_worker, do_arp_request, packet); worker_wait(&arp_worker); }

fill_ethernet_header(packet); packet_send(); }

static ip_init(void) { worker_init(&arp_worker); }