Note: there is still an issue I've realised in that writer_flush() could
potentially result in a single packet being written out of order as two
threads have the potential to write. This isn't fatal and is probably
rare enough to ignore at this stage.