Figure 3 in the paper shows that under some circumstances, updating shared state can be faster using a message-passing style than a shared memory style.
We'll explore message-passing in the context of a simple counter (shared memory is certainly the faster approach for something as simple as a counter, but the trade-off is more interesting for larger structures). The shared-memory version of our program simply increments one shared variable from multiple threads:
int counter; // shared counter that is cache-line aligned
thread()
{
while (1) {
atomic_increment(&counter);
}
}
Sketch out what the message-version for the microbenchmark is. That is, how do you use shared-memory to communicate a cache-line to a single server thread? Here is a start:
server()
{
int server_counter; // not shared, just the server accesses it.
while (1) {
int client_id;
r = wait_for_request(&client_id);
server_counter++;
send_response(client_id, server_counter);
}
}
client()
{
send_request(client_id);
int count = receive_response();
}
Submit: Complete the code for the wait_for_request, send_response, send_request, and receive_response.