@@ -70,9 +70,11 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7070/*********************************************************************/
7171
7272#include "common.h"
73- #ifdef OS_LINUX
73+ #if defined( OS_LINUX ) || defined( OS_NETBSD ) || defined( OS_DARWIN )
7474#include <dlfcn.h>
75+ #include <signal.h>
7576#include <sys/resource.h>
77+ #include <sys/time.h>
7678#endif
7779
7880#ifndef likely
@@ -265,7 +267,7 @@ int get_node(void);
265267
266268static int increased_threads = 0 ;
267269
268- static int blas_thread_server (void * arg ){
270+ static void * blas_thread_server (void * arg ){
269271
270272 /* Thread identifier */
271273 BLASLONG cpu = (BLASLONG )arg ;
@@ -458,7 +460,7 @@ static int blas_thread_server(void *arg){
458460
459461 //pthread_exit(NULL);
460462
461- return 0 ;
463+ return NULL ;
462464}
463465
464466#ifdef MONITOR
@@ -565,14 +567,23 @@ int blas_thread_init(void){
565567
566568#ifdef NEED_STACKATTR
567569 ret = pthread_create (& blas_threads [i ], & attr ,
568- ( void * ) & blas_thread_server , (void * )i );
570+ & blas_thread_server , (void * )i );
569571#else
570572 ret = pthread_create (& blas_threads [i ], NULL ,
571- ( void * ) & blas_thread_server , (void * )i );
573+ & blas_thread_server , (void * )i );
572574#endif
573575 if (ret != 0 ){
574- fprintf (STDERR ,"OpenBLAS: pthread_creat error in blas_thread_init function. Error code:%d\n" ,ret );
575- exit (1 );
576+ struct rlimit rlim ;
577+ const char * msg = strerror (ret );
578+ fprintf (STDERR , "OpenBLAS blas_thread_init: pthread_create: %s\n" , msg );
579+ if (0 == getrlimit (RLIMIT_NPROC , & rlim )) {
580+ fprintf (STDERR , "OpenBLAS blas_thread_init: RLIMIT_NPROC "
581+ "%ld current, %ld max\n" , (long )(rlim .rlim_cur ), (long )(rlim .rlim_max ));
582+ }
583+ if (0 != raise (SIGINT )) {
584+ fprintf (STDERR , "OpenBLAS blas_thread_init: calling exit(3)\n" );
585+ exit (EXIT_FAILURE );
586+ }
576587 }
577588 }
578589
@@ -832,10 +843,10 @@ void goto_set_num_threads(int num_threads) {
832843
833844#ifdef NEED_STACKATTR
834845 pthread_create (& blas_threads [i ], & attr ,
835- ( void * ) & blas_thread_server , (void * )i );
846+ & blas_thread_server , (void * )i );
836847#else
837848 pthread_create (& blas_threads [i ], NULL ,
838- ( void * ) & blas_thread_server , (void * )i );
849+ & blas_thread_server , (void * )i );
839850#endif
840851 }
841852
0 commit comments