So I tested it on my side with following code:

t.dll:
__thread int g_var = 1;

__declspec(dllexport) int get_g_var (void)
{
  return g_var;
}

__declspec(dllexport) void set_g_var (int v)
{
  g_var = v;
}

and t2.exe:
#include <windows.h>
#include <stdio.h>

typedef int (*f1)(void);
typedef void (*f2)(int);

int main()
{
  HINSTANCE h = LoadLibrary ("t.dll");
  f1 get;
  f2 set;

  if (!h)
    { printf ("Failed to load t.dll\n");  return 0; }
  get = (f1) GetProcAddress (h, "get_g_var");
  set = (f2) GetProcAddress (h, "set_g_var");
  if (!get || !set)
   { printf ("Imports not present in t.dll\n"); return 0; }

  printf ("g_var = %d\n", (*get) ());
  (*set)(2);
  printf ("g_var = %d\n", (*get) ());
  FreeLibrary (h);
  return 0;
}

It works for mingw-w64 for 32-bit and 64-bit.  I assume the code in
question for this is in crtdllt.c:
...
      if (__dyn_tls_init_callback != NULL)
        {
          __dyn_tls_init_callback (hDllHandle, DLL_THREAD_ATTACH, lpreserved);
        }
..


As far as I see is mingw.org not synchronizing with loading of
msvcrt.dll, so code is here quite different to that what happens in
mingw-w64.

Regards,
Kai

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to