Question

Googling don't find anything. Are they created at point of use, or are the generic parts shared between instances?

(Same for template classes?)

Was it helpful?

Solution

Template functions are created at compile time. The template property is completely orthogonal to thread-safety.

OTHER TIPS

They're no more or less thread-safe than any other type of function.

The only way I can think of thread safety being affected by this is that if someMethod<typename T>() wasn't thread safe then it would still be okay for a thread to operate on someMethod<int>() while another worked on someMethod<std:string>(), as long as the lack of thread-safety didn't come from their both calling into some non-templated function.

The situation where something else is guaranteeing that only one thread is doing a particular task with a particular type at a time seems pretty unlikely though.

Template functions are simply ...templates used by the compiler to generate "normal" functions. So it's the same as normal functions, there is no difference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top