[colug-432] a little threaded programming prep

Paul Dubuc work at paul.dubuc.org
Mon May 1 13:39:57 EDT 2017


Rick Troth wrote:
> I have a question about C and thread-safe programming.
> When I define automatic variables in a function, are those taken from thread
> storage or from global/common storage? In other words, if I have 17 threads
> which might call the same plain function, do I need to do anything special in
> that function so they don't step on each other? (Here "special" meaning more
> than simply NOT marking variables as extern or static.)
>
> I've never done threaded C per se. (Have done even driven in C and assembler
> enough times. Hate to think I'm a total noob. But ... dragons and land minds
> ... lots I don't know.)
>
> Thanks!
>
> -- R; <><

Automatic (local) variables are on the thread local stack.  Each thread has 
its own copy.  Global, static variables need to be protected by a mutex or 
some other thread locking mechanism.

Paul



More information about the colug-432 mailing list