[OT] This feels wrong (pthreads question)

Dave Smith dave at thesmithfam.org
Sun Jan 28 15:53:44 MST 2007

Steve wrote:
> And it works, but it feels very wrong to me.  Having to cast the
> object to void, then recast back to it's original form, seems like a
> lot of overhead as well as being dangerous.  And it has to occur every
> 250 ms, which seems like alot of recasting to me.

You are right. Using pthreads with C++ classes is awkward. That's just 
the way it is.

Most people write a thread class with a pure virtual run() method like 
you've done that you can then sub-class to get a custom thread. This 
cleans up the code, and isolates the awkward stuff to one place, but the 
casting is still there. It's called thunking by the way (usage: "I've 
designed a class to thunk pthreads into a C++ class").


More information about the PLUG mailing list