[Insight-developers] thread safety question

Paul Hughett hughett@mercur.uphs.upenn.edu
Fri, 16 Feb 2001 09:45:23 -0500


Will Schroeder:

> Also, since we are trying to build a toolkit that allows users to
> assemble pieces arbitrarily, we have to be careful how these
> auxiliary functions to interact with the rest of the system. If they
> assume too much about the invoking class, then it can make it
> too hard to use the functions.

I would recommend the policy that methods be thread-safe unless there's
some compelling reason not to be; and that any unsafe methods be clearly
marked as such in their Doxygen descriptions.


> Note: you could always set up the auxiliary class/functions to
> accept a "structure" as part of the invocation/instantiation. This
> structure would serve as the scratch space, and could be allocated
> just once per thread.

My understanding of C is that automatic variables are essentially
free, because you can allocate any number of them at once simply by
incrementing the stack pointer.  (Initialization costs extra, but
would need to be done in either case.)  Is this also the case for C++?

Paul Hughett