[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: luuid vs. forks
- From: Sam Roberts <vieuxtech@...>
- Date: Mon, 8 Feb 2010 14:12:18 -0800
On Mon, Feb 8, 2010 at 1:50 PM, Alexander Gladysh <firstname.lastname@example.org> wrote:
>>> This looks wrong to me. Also it (indirectly) breaks my tests. So I want to
>>> ask — is this normal, or my setup is broken?
>> it _is_ very wrong. what happens if you run the program a second
>> time? do you get the same sequence? or is it different each time but
>> the same on both forks()?
> I get different sequences each time I run the program. But they are
> the same on both forks.
It's possible libuuid is defaulting to the time-based algorithm on OS
X, which IIRC uses an internal count so
consecutive UUIDs are different, but if the system time doesn't
change, which it might not if 5 quick calls can be made within the
timer resolution, the UUIDs can be the same for multiple
almost-simultaneous uses of the generator.
You could try sleeping for a few seconds in the parent, and see if
that gives you different UUIDs. If its defaulting to time-based, using
the random-based algorithm might work better for you.
If you are using roberto's luuid binding, it looks like you can choose
const char *t=luaL_optstring(L,1,NULL);
if (t==NULL) uuid_generate(c); else
if (*t=='r') uuid_generate_random(c); else
if (*t=='t') uuid_generate_time(c); else uuid_generate(c);
> Thank you. But, unfortunately, I do not see a way to seed libuuid's
> PRG at all. It seems that the library does that by itself.
Since you don't have source for apple's libuuid, its hard to know what
it's doing. Have you checked if it has docs? Or maybe looked at its
header file? There might be a clue, you might at least learn that it
is an opensource lib, of a particular version. If you find the code it
would probably be immediately obvious what is going wrong.