Re: [ANNOUNCE] CGit v0.1-pre

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Sunday, December 10, 2006 - 6:04 pm

On Mon, 11 Dec 2006, Lars Hjemli wrote:

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? 

		Linus
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[ANNOUNCE] CGit v0.1-pre, Lars Hjemli, (Sun Dec 10, 4:42 pm)
Re: [ANNOUNCE] CGit v0.1-pre, Linus Torvalds, (Sun Dec 10, 6:04 pm)
Re: [ANNOUNCE] CGit v0.1-pre, Lars Hjemli, (Mon Dec 11, 1:33 am)
Re: [ANNOUNCE] CGit v0.1-pre, Lars Hjemli, (Mon Dec 11, 4:59 am)
Re: [ANNOUNCE] CGit v0.1-pre, Linus Torvalds, (Mon Dec 11, 10:01 am)
Re: [ANNOUNCE] CGit v0.1-pre, Linus Torvalds, (Mon Dec 11, 10:33 am)
Re: [ANNOUNCE] CGit v0.1-pre, Lars Hjemli, (Mon Dec 11, 10:40 am)
Re: [ANNOUNCE] CGit v0.1-pre, Linus Torvalds, (Mon Dec 11, 11:18 am)
Re: [ANNOUNCE] CGit v0.1-pre, Lars Hjemli, (Mon Dec 11, 11:38 am)