04-10-2009
4,
0
Join Date: Dec 2007
Last Activity: 30 December 2009, 6:12 PM EST
Posts: 4
Thanks Given: 0
Thanked 0 Times in 0 Posts
Thread local storage on ancient AIX
What I'm given:
Pure C code in one file that has to compile on Windows, SunOS, and AIX. My task is making minimal changes to the code to make it thread safe. I'm not in control of threads - they are created elsewhere. The code has a function invoked externally. The first call to this function is solitary. I.e. I'm guaranteed that no other call in any other thread will be made until it returns. It allows me to initialize mutexes during that call. The task seems very easy to accomplish with pthread library.
However, there is a complication. There are situations, when two consecutive calls to the function within a thread are related, and the first needs to pass some information to the next call. The natural way to accomplish it is to declare a thread local variable in global context. For this I use __thread directive, and it seems to work perfectly on SunOS. For AIX, on the other hand, this does not work. Since for our compilation we use the least common denominator for the broadest support, AIX complains that __thread directive is not compatible with the platform.
1. Is there anything AIX specific that allows to declare thread local variable in global context besides __thread directive?
2. What would be the most elegant (least code changes) work around?