• Y
    Ensure the destruction order of PosixEnv and ThreadLocalPtr · 00d6edf6
    Yueh-Hsuan Chiang 提交于
    Summary:
    By default, RocksDB initializes the singletons of ThreadLocalPtr first, then initializes PosixEnv
    via static initializer.  Destructor terminates objects in reverse order, so terminating PosixEnv
    (calling pthread_mutex_lock), then ThreadLocal (calling pthread_mutex_destroy).
    
    However, in certain case, application might initialize PosixEnv first, then ThreadLocalPtr.
    This will cause core dump at the end of the program (eg. https://github.com/facebook/mysql-5.6/issues/122)
    
    This patch fix this issue by ensuring the destruction order by moving the global static singletons
    to function static singletons.  Since function static singletons are initialized when the function is first
    called, this property allows us invoke to enforce the construction of the static PosixEnv and the
    singletons of ThreadLocalPtr by calling the function where the ThreadLocalPtr singletons belongs
    right before we initialize the static PosixEnv.
    
    Test Plan: Verified in the MyRocks.
    
    Reviewers: yoshinorim, IslamAbdelRahman, rven, kradhakrishnan, anthony, sdong, MarkCallaghan
    
    Reviewed By: anthony
    
    Subscribers: dhruba, leveldb
    
    Differential Revision: https://reviews.facebook.net/D51789
    00d6edf6
thread_local.cc 11.3 KB