I have global static variables in a C library, which generate exceptions in a multithread run. I need to make them safe in some way (i.e., each thread should relate to a different instance of these variables). Any recommended methods?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no standard way that works across all C implementations, but implementation-specific solutions exist. For example, with Microsoft’s compiler (see the docs),
makes
tls_ilive in thread-local storage (each thread has its own separate instance of this variable). With gcc, the syntax isYou may also want to check the wikipedia entry on the subject.