{ ## main loop if (cache_is_good()) { show_cache_and_exit("current"); } if (cache_is_stale()) { if (i_am_the_writer()) { if (i_can_fork()) { if (i_am_the_parent()) { show_cache_and_exit("stale"); } ## child does: be_a_child(); update_cache(); exit 0; } ## cannot fork, so it's up to me update_cache(); show_cache_and_exit("current"); } ## I'm not the writer, so show old cache show_cache_and_exit("stale"); } ## cache is dead if (i_am_the_writer()) { update_cache(); show_cache_and_exit("current"); } ## we cannot do anything about a bad cache, so retry close_cache(); sleep 5; redo; }