Re: [ANNOUNCE] CGit v0.1-pre
From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-08-11 20:10:56
On Mon, 11 Dec 2006, Lars Hjemli wrote:
For a quick summary of the cache algorithm, the project README is here: http://hjemli.net/git/cgit/view/?id=5917c37ce30b3f0a374c9fa376955f51f1d7bfbf
Your pseudo-algorithm is dubious:
name = generate_cache_name(request);
top:
if (!exists(name)) {
if (lock_cache(name)) {
generate_cache(request, name);
unlock_cache(name);
} else {
sched_yield();
goto top;
}
} else if (expired(name)) {
if (lock_cache(name)) {
generate_cache(request, name);
unlock_cache(name);
}
}
print_file(name);
You really should have:
if (!exists) {
if (!lock)
delay-and-repeat;
/* RETEST exists _after_ getting the lock */
if (!exists) {
generate into lock-file
mv lockfile exists;
} else {
rm lockfile
}
}
because you really want to re-check the existence after you got the lock,
otherwise you would race with somebody else that got the lock, generated
the data, and then unlocked (and you got the lock _after_ the data was
generated, so now you generate it unnecessarily).
As a side note: how do you release your caches?