Skip to content

Commit 70642fe

Browse files
committed
Refs #668. Raise the signal when pthread_create fails.
Thank James K. Lowden for the patch.
1 parent 79d4a62 commit 70642fe

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ before_build:
3939
- cmake -G "Visual Studio 12 Win64" .
4040

4141
test_script:
42-
42+
- echo Build OK!

driver/others/blas_server.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

266268
static 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

Comments
 (0)