This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

libstdc++ / mt_allocator.cc when using gthreads


All,

The enclosed testcases (very close to ext/mt_allocator/deallocate_global_thread-1.cc) exposes a pattern where the following sequence is called (when __gthread_active_p is enabled) :

    __gthread_key_create(&key,::_M_destroy_thread_key);
    __gthread_setspecific(key, (void*)_M_id);
    __gthread_key_delete(key);
    __gthread_setspecific(key, (void*)_M_id);


Even, if this works perfectly using pthreads, it seems to me that this is an illegal use of threads. When using another thread implementation, (i.e. when the key is implemented as a pointer). In my case:
- the key_create allocates the memory, and returns the pointer to the allocated memory
- the key_delete frees this memory,
- the setspecific uses this freed memory.


If I m right saying this is an illegal use of threads, a possible quick patch for mt_allocator.cc could be the one enclosed.

Let me know what you think of this approach.

Thanks.
Laurent


Attachment: deallocate_global_thread-5.cc
Description: Text document

Attachment: illegal_thread_key_used.patch
Description: Text document


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