[tpm] fork and blessed hash references
Rob Janes
janes.rob at gmail.com
Thu Jan 14 08:49:30 PST 2010
check out Time::HiRes for alarms with granularity less than one second.
the perl ipc stuff allows you to access a shared memory region. From
a c perspective, the ipc shared memory is truly shared. I looked at
the perl shared memory code, and I believe what it does is copy the
shared memory region into a perl variable. Updates to the shared
memory must be copied back manually via call to perl ipc method.
In order to make this work, you'll also have to get a semaphore to
serialize access to the shared memory region.
there is an alternative process. set a signal handler for one of the
user signals SIGUSR1 say. Send a signal to that process and handler
to reset the timer. Your SIGALRM handler then is in a process which
also has a SIGUSR1 handler. The SIGUSR1 handler resets the timer.
This way you don't need shared memory or semaphores. Much easier,
much less complicated. All that needs to be known globally is the pid
(process id) and maybe the tid (thread id) of the SIGUSR1 handler.
-rob janes
arjay at cpan.org
On Thu, Jan 14, 2010 at 11:25 AM, Stuart Watt <stuart at morungos.com> wrote:
> Madison Kelly wrote:
>>
>> However, that led us to 'alarm', which might just be the ticket.
>>
>> The idea is; Setup a SIGALARM handler that shuts down the daemon, then on
>> setup set an alarm for X time in the future. After that, each method call
>> can call 'alarm' for Y time in the future, hopefully clearing the current
>> pending alarm(s) and pushing the back into the future. Once there is enough
>> time with no activity, the SIGALARM will call the handler and will shut down
>> the daemon.
>
> alarm works very well for timeouts - we even use it on Windows, which breaks
> fork() even more. If notification is all you need, not data sharing, its all
> fairly straightforward.
>
> For data sharing, it sounds slightly crazy, but the simplest solution for us
> was to use DBI and SQLite, with its exclusive transactions. These allows us
> to coordinate safe data access between processes, and it works on all
> platforms safely.
>
> All the best
> Stuart
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
More information about the toronto-pm
mailing list