<commit_before>// @(#)root/thread:$Id$
// Author: <NAME>   02/07/97

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TPosixThread                                                         //
//                                                                      //
// This class provides an interface to the posix thread routines.       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TPosixThread.h"


ClassImp(TPosixThread)


//______________________________________________________________________________
Int_t TPosixThread::Run(TThread *th)
{
   // Create a pthread. Returns 0 on success, otherwise an error number will
   // be returned.

   int det;
   pthread_t id;
   pthread_attr_t *attr = new pthread_attr_t;

   pthread_attr_init(attr);

   // Set detach state
   det = (th->fDetached) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE;

   pthread_attr_setdetachstate(attr, det);

#ifdef R__MACOSX
   // See https://developer.apple.com/library/mac/#qa/qa1419/_index.html
   // Linux has 2MB of stack per thread, so use the same:
#define R__REQUIRED_STACK_SIZE 1024*1024*2
   size_t stackSize = 0;
   if (!pthread_attr_getstacksize(attr, &stackSize)
       && stackSize < R__REQUIRED_STACK_SIZE) {
      pthread_attr_setstacksize(attr, R__REQUIRED_STACK_SIZE);
   }
#endif
   int ierr = pthread_create(&id, attr, &TThread::Function, th);
   if (!ierr) th->fId = (Long_t) id;

   pthread_attr_destroy(attr);
   delete attr;

   return ierr;
}

//______________________________________________________________________________
Int_t TPosixThread::Join(TThread *th, void **ret)
{
   // Join  suspends  the  execution  of the calling thread until the
   // thread identified by th terminates, either by  calling  pthread_exit
   // or by being cancelled. Returns 0 on success, otherwise an error number will
   // be returned.

   return pthread_join((pthread_t) th->fId, ret);
}

//______________________________________________________________________________
Int_t TPosixThread::Exit(void *ret)
{
   // Terminates the execution of the calling thread. Return 0.

   pthread_exit(ret);<commit_msg>More generic version of r42885: guarantee thread stack size to be >= 2MB on all platforms.<commit_after>// @(#)root/thread:$Id$
// Author: <NAME>   02/07/97

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TPosixThread                                                         //
//                                                                      //
// This class provides an interface to the posix thread routines.       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TPosixThread.h"


ClassImp(TPosixThread)


//______________________________________________________________________________
Int_t TPosixThread::Run(TThread *th)
{
   // Create a pthread. Returns 0 on success, otherwise an error number will
   // be returned.

   int det;
   pthread_t id;
   pthread_attr_t *attr = new pthread_attr_t;

   pthread_attr_init(attr);

   // Set detach state
   det = (th->fDetached) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE;

   pthread_attr_setdetachstate(attr, det);

   // See e.g. https://developer.apple.com/library/mac/#qa/qa1419/_index.html
   // MacOS has only 512k of stack per thread; Linux has 2MB.
   const size_t requiredStackSize = 1024*1024*2;
   size_t stackSize = 0;
   if (!pthread_attr_getstacksize(attr, &stackSize)
       && stackSize < requiredStackSize) {
      pthread_attr_setstacksize(attr, requiredStackSize);
   }
   int ierr = pthread_create(&id, attr, &TThread::Function, th);
   if (!ierr) th->fId = (Long_t) id;

   pthread_attr_destroy(attr);
   delete attr;

   return ierr;
}

//______________________________________________________________________________
Int_t TPosixThread::Join(TThread *th, void **ret)
{
   // Join  suspends  the  execution  of the calling thread until the
   // thread identified by th terminates, either by  calling  pthread_exit
   // or by being cancelled. Returns 0 on success, otherwise an error number will
   // be returned.

   return pthread_join((pthread_t) th->fId, ret);
}

//______________________________________________________________________________
Int_t TPosixThread::Exit(void *ret)
{
   // Terminates the execution of the calling thread. Return 0.

   pthread_exit(ret);
{'fraction_non_alphanumeric': 0.18234064785788923, 'fraction_numerical': 0.012713340299547196, 'mean_word_length': 1.7757370710488158, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4018168', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1341, 'n_words': 366}