Call _thread_init() from pthread_once() if it has not already been called.

This fixes a segfault in some C++ programs which use exceptions before
main() has been called (i.e. from global constructors).

Reviewed by: deischen
This commit is contained in:
dfr 2000-07-21 09:31:13 +00:00
parent 4e34488c31
commit 5c6b23bd7c
3 changed files with 6 additions and 0 deletions

View File

@ -39,6 +39,8 @@ int
pthread_once(pthread_once_t * once_control, void (*init_routine) (void))
{
if (once_control->state == PTHREAD_NEEDS_INIT) {
if (_thread_initial == NULL)
_thread_init();
pthread_mutex_lock(&(once_control->mutex));
if (once_control->state == PTHREAD_NEEDS_INIT) {
init_routine();

View File

@ -39,6 +39,8 @@ int
pthread_once(pthread_once_t * once_control, void (*init_routine) (void))
{
if (once_control->state == PTHREAD_NEEDS_INIT) {
if (_thread_initial == NULL)
_thread_init();
pthread_mutex_lock(&(once_control->mutex));
if (once_control->state == PTHREAD_NEEDS_INIT) {
init_routine();

View File

@ -39,6 +39,8 @@ int
pthread_once(pthread_once_t * once_control, void (*init_routine) (void))
{
if (once_control->state == PTHREAD_NEEDS_INIT) {
if (_thread_initial == NULL)
_thread_init();
pthread_mutex_lock(&(once_control->mutex));
if (once_control->state == PTHREAD_NEEDS_INIT) {
init_routine();