Boost logo

Boost Users :

From: Rob Desbois (rob.desbois_at_[hidden])
Date: 2008-02-11 04:48:48


On Feb 10, 2008 2:55 PM, Paul J R <me_at_[hidden]> wrote:
> Now, i know if i overload the threadcontroller class in B it'd solve all
> my problems, but the real threadcontroller method is alot more complex and
> class A has about 6 sub classes so replicating the threadcontroller in
> each of the classes would be a little tedious.
>
> Have i stumbled across a bug, or is that how its supposed to work?

That's how it's supposed to work; in A::threadcontroller():
> A *mea = factory();
> mea->worker();
> thre.create_thread(*mea);
I think if you dereference a variable of type A* you get, and will
always get, an object of type A. At compile-time the compiler won't
know whether the A* will point to an A or B, which doesn't matter with
pointer/reference semantics but does matter when the *object* is being
passed as the compiler must know how much stack space to reserve for
it. In this case it only knows to reserve enough for an A instance.

I think you may have to define a method in A and B, similar to this:

virtual void spawn(boost::thread_group& thre, A* worker) {
   thre.create_thread(worker);
}

Override it in B but it should then take a B* not A*. There may be a
better way but this is what sprung to mind first off.

HTH
--rob


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net