[SciPy-user] shared memory machines
Mon Feb 9 23:05:42 CST 2009
On Feb 9, 2009, at 4:41 PM, Sturla Molden wrote:
>>> In that case I could rewrite the object to pickle the shmid instead
>>> of a
>>> random name (uuid string) on System V.
>> But you need the key, not the id, to pass to shmget() to get a handle
>> to an existing IPC object.
> Yes, but if we use the shmid, we have the handle. So we can pass that
> integer from one process to another. At least that is what my old
> book on
> Linux programming describes. Since you say I need to use shmget, can I
> assume this method is not valid on all Unix incarnations?
No, sorry, ignore what I said. I was not thinking clearly.
>> If I were you, rather than trying to figure out how broken ftok() is
>> (and it might be broken in different ways on different platforms),
>> just abandon it altogether. It's not as if generating a random number
>> instead is difficult. In fact, it's easier. Instead of generating a
>> random uuid and passing that to ftok(), eliminate the middleman and
>> generate a random key yourself.
> It has to be a unique key for the system, not just a random number.
> So I
> could try to call shmget multiple times with IPC_EXCL until it
> Then I'll have to check why it failed as well.
Exactly. It's a pain in the arse but it is what must be done.
> This is the first time I have found Windows to be the less annoying
Indeed, that's a rare occurrence. The POSIX API is better than Sys V
in that there's a much larger "key" space, so large that collisions
between randomly generated ids are statistically...hmmm, maybe I
should watch my mouth on a statistically-oriented mailing list. =)
Under POSIX, an IPC object's name is a string that starts with a
slash. Under FreeBSD (the most restrictive API I've encountered), the
name is limited to 14 filename-permissible characters. Subtracting the
leading slash, that's space for 13 alphanumeric characters plus
underscore and dot. Filenames permit 52 upper and lowercase characters
plus 10 digits plus 2 punctuation characters = 64 characters. 64**13
is a lot more choices than INT_MAX. So OK, I stand by my statement.
How does the Windows API resolve name/key collisions?
> Thanks for your help. :-)
Glad to be able to provide it. (Ni är välkomna.)
More information about the SciPy-user