thread safing dlls

Dmitry Timoshkov dmitry at baikal.ru
Mon Dec 3 22:17:36 CST 2001


"Michael Zayats" <zmichael at regard.co.il> wrote:

> I have a dll that is not thread safe (i.e. has many global variables, about
> 500). I have the sources for the dll.
> The target is to make it thread safe.
> 
> Moving all the variables to thread specific storage is very complicated.
> Making it thread safe on ansi C level is very, very complicated too. I guess
> that you thoroughly deal with PE format.
> 
> Is there a way to play with executable sections, such that every thread will
> use it's own copy of the data?
> 
> I know one guy, that claimed that he has achieved this with 20 lines of code
> by directly modifying smth in executable, he doesn't want to tell me what he
> has done :(
> 
> I also heard of __attribute((section... in gcc that should do the work (I am
> generally talking about windoze platform only), can you explain me what does
> it do in gcc?

All you need is to place all initialized data you want to make thread safe
to a separate section and then place a pointer to that data in the PE header
[IMAGE_FILE_THREAD_LOCAL_STORAGE]. Creating custom section is an easy part,
but I don't know how to fulfill the second part with gcc.

-- 
Dmitry.





More information about the wine-devel mailing list