Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76752 - trunk/libs/thread/src/win32
From: vicente.botet_at_[hidden]
Date: 2012-01-28 11:02:02


Author: viboes
Date: 2012-01-28 11:02:01 EST (Sat, 28 Jan 2012)
New Revision: 76752
URL: http://svn.boost.org/trac/boost/changeset/76752

Log:
Thread: Try to fix 4885 - Access violation in set_tss_data at process exit due to invalid assumption about TlsAlloc
Text files modified:
   trunk/libs/thread/src/win32/thread.cpp | 23 ++++++++++++-----------
   1 files changed, 12 insertions(+), 11 deletions(-)

Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2012-01-28 11:02:01 EST (Sat, 28 Jan 2012)
@@ -27,32 +27,33 @@
     namespace
     {
         boost::once_flag current_thread_tls_init_flag=BOOST_ONCE_INIT;
- DWORD current_thread_tls_key=0;
+ #if defined(UNDER_CE)
+ // Windows CE does not define the TLS_OUT_OF_INDEXES constant.
+ DWORD tls_out_of_index=0xFFFFFFFF;
+ #else
+ DWORD tls_out_of_index=TLS_OUT_OF_INDEXES;
+ #endif
+ DWORD current_thread_tls_key=tls_out_of_index;
 
         void create_current_thread_tls_key()
         {
             tss_cleanup_implemented(); // if anyone uses TSS, we need the cleanup linked in
             current_thread_tls_key=TlsAlloc();
- #if defined(UNDER_CE)
- // Windows CE does not define the TLS_OUT_OF_INDEXES constant.
- BOOST_ASSERT(current_thread_tls_key!=0xFFFFFFFF);
- #else
- BOOST_ASSERT(current_thread_tls_key!=TLS_OUT_OF_INDEXES);
- #endif
+ BOOST_ASSERT(current_thread_tls_key!=tls_out_of_index);
         }
 
         void cleanup_tls_key()
         {
- if(current_thread_tls_key)
+ if(current_thread_tls_key!=tls_out_of_index)
             {
                 TlsFree(current_thread_tls_key);
- current_thread_tls_key=0;
+ current_thread_tls_key=tls_out_of_index;
             }
         }
 
         detail::thread_data_base* get_current_thread_data()
         {
- if(!current_thread_tls_key)
+ if(current_thread_tls_key==tls_out_of_index)
             {
                 return 0;
             }
@@ -62,7 +63,7 @@
         void set_current_thread_data(detail::thread_data_base* new_data)
         {
             boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
- if(current_thread_tls_key)
+ if(current_thread_tls_key!=tls_out_of_index)
                 BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data));
             else
                 boost::throw_exception(thread_resource_error());


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk