CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: The use of TLS

  1. #1
    Join Date
    Apr 1999
    Posts
    37

    The use of TLS

    I have a question about TLS.
    I put below code into both EXE and DLL

    #define TLS __declspec(thread)
    TLS int a;

    In multithread, the EXE program is working well.
    But DLL program attached to multithreading program such as IIS isn't working.
    In In-Process COM, also is not working.

    I want to use TLS in COM. But I'm not convinced that this is realizable.

    Is it OK if I believe TLS will be well working in COM?

    A programmer who loves Goethe.

  2. #2
    Guest

    Re: The use of TLS

    I know that we should not use TLS in COM as COM calls do not have any thread-affinity. In other words, calls to the same object need not arrive on the same thread(s).


  3. #3
    Join Date
    Oct 2002
    Location
    India
    Posts
    138
    hello,

    Do any one know more about why the dll crashes when TLS is used.I used in one simple dll the TLS it works fine.
    If any one knows more about TLS and dll please post reply. One thing i noted that when i use TLS(Thread local storage) the is entry in .tls section but no entry in TlsTable in Data Directory why? is only with borland or any other complier it creates the entry in TlsTable in Data Directory ???

    Regards,
    Thomas

  4. #4
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    If we look at the documentation of __declspec(thread), we can find this, "The use of __declspec(thread) may interfere with delay loading of DLL imports." and regarding the constraint MSDN says this
    Delay loading of a DLL may not result in the same behavior of the process if there are per-process initializations that occur in the entry point of the delay-loaded DLL. Other cases include static TLS (thread local storage, declared using __declspec(thread) which is not handled when the DLL is loaded via LoadLibrary. Dynamic TLS, using TlsAlloc,TlsFree,TlsGetValue,TlsSetValue is still available for use in either static or delay-loaded DLLs.
    This is the reason why statically linking a dll will work fine, but using it in COM or other methods that uses Loadlibrary will fail.

    Hope it will clarify your concern

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured