This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: TLS problem


While tracking down the problems with a threaded perl i recognized a
problem with TLS that is probably the reason for the forked child crash:

The TLS is not synced between parent and child. If i run my test program

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>

int main(void)
{
  int w_key = TlsAlloc ();
  TlsSetValue (w_key, (void*) 0x10);

  switch (fork())
    {
    case -1:
      return 0;
    case 0:
      printf ("child : %p\n", TlsGetValue (w_key));
      break;
    default:
      wait (NULL);
      printf ("parent: %p\n", TlsGetValue (w_key));
    }

  return 0;
}

i get

child : 0x0
parent: 0x10

Since perl use TLS (pthread keys to be true, but this will be mapped to
win32 TLS) to store the perl interpreter reference the child will crash
because the reference is NULL.

IMHO the are two possible solutions:
1. Synchronize the win32 TLS array between parent and child.
2. Create a cygwin only solution that will use its own tls array like CGFs
experimental TLS implementation.

I would prefer solution 1 because it will more general, consider that a
cygwin app can use the WIN32 TLS functions and not the pthread ones.

Thomas


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]