IPC and counters

Simon Wistow simon at thegestalt.org
Tue Oct 14 23:21:18 BST 2008

I have an IPC problem.

I have a parent process with a bunch of forked children.

The parent sits in a loop waiting for messages and occasionally passes 
them onto the children which are also sitting in their own loops 
listening for messages and then doing stuff with them. 

Still with me?

Now occasionally, if a Child gets sent a message then it doesn't want 
any of the other Children to do anything. 

So what I think is something like this.


    my $n  = scalar(@children);
    my $id = $message->id;
    create_ipc_counter("$id-lock", 0);
    foreach my $child (@children) {


    my $message = get_message();
    my $id      = $message->id;

    # If we're the first ...
    if (inc_ipc_counter("$id-lock")==1) {
    # ... otherwise ignore it

    # If we're the last then clean up
    if (dec_ipc_count("$id-count")==0) {

Is there some sort of module which will do similar? Or am I smoking huge 
quanities of crack?

Is there another way to do this?


More information about the london.pm mailing list