[SciPy-user] shared memory machines
Mon Feb 9 11:49:06 CST 2009
On Feb 9, 2009, at 11:42 AM, Sturla Molden wrote:
> On 2/9/2009 4:07 PM, Philip Semanchuk wrote:
>> Unfortunately POSIX IPC doesn't report that information.
> I'll suggest we use System V IPC instead, as it does report a ref
> count. Code example attached. It compiles with Cython but I have not
> done any testing except that.
> My suggestion is to spawn a thread in the creator process to monitor
> the attachment count for the segment, and mark it for removal when
> it has dropped to zero. There is a __dealloc__ in a Handle object
> that does the shmdt, and then Python should do the refcounting
> (similar to what is done for CloseHandle in Windows).
If you're destroying the segment when the attach count drops to zero,
why not check that immediately after the call to shmdt()?
> key = ftok( <char *> (self.name), 0)
ftok() should probably be avoided as it returns duplicate keys:
I'd recommend using a random number generator instead. I believe a
key_t is guaranteed to fit into an int, so you could generate a random
number anywhere from 1 to INT_MAX, taking care not to step on the
value IPC_PRIVATE (unless you want to assume that that is always
#defined to 0).
More information about the SciPy-user