Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-02-04 10:27:29

Angus Leeming wrote:

>I'm playing here with some child_process code and have a singleton class
>that monitors the status of all the child processes using
>I was thinking that I need a sort of Zombie policy rather than a Phoenix
>policy for my singleton. Ie, if its deleted and then called again it
>should be resurrected but flagged as dissabled. There's no need for it to
>go on to inform the rest of the (possibly/probably dead) program that a
>child process has just exited.
>Does that make sense? Could you add this to your list of available
>I'm out of town for a week. Will respond to any answers you give
Excellent idea! Your suggestion gave me an idea for a more general
solution... an allocator which is templated with two other allocator
types, and uses the first on the first allocation and the second on any
subsequent allocation. Thus, the first allocator could alloc using new,
or malloc, or statically, however you please, and the second could throw
an exception, return null, or maybe just call a different constructor
entirely. For your case in particular, I am providing a BoolAllocator,
which just passes a boolean flag to the ctor. You might use such a
policy as follows:

class Zombie : public Singleton < Zombie, /*Selected Lifetime Policy*/ <
/*other stuff*/,
OneTimeAlloc < BoolAlloc < true > :: Allocator, BoolAlloc < false > ::
Allocator > :: Allocator >
    bool dead;

    Zombie ( bool invalid ) : dead ( invalid )

    ~ Zombie ( )

    void foo ( )
        if ( !dead )
            /*do work here*/


Boost list run by bdawes at, gregod at, cpdaniel at, john at