errno inappropriate for pthread_create

Robert Sachunsky <[email protected]>
Newsgroups gmane.lisp.scheme.bigloo
Message-ID <[email protected]>
Hi Manuel,

happy new year!

Being unable to accomplish `make test` on the December version of 
bigloo4.3a, and seeing strange error messages, I went to check on...

   api/srfi18/src/Posix/cthread.c
   api/pthread/src/Posix/bglpthread.c

...and I believe those inappropriately use errno for reporting after 
pthread_create. In contrast, pthread_join already gets it right. See 
below for a patch to fix that.

(The test did succeed after increasing stack size limit beyond 6MB. No 
idea why -- I am *not* building on Android/Darwin.)

Regards,
Robert
pthread_create.patch (text/x-patch, 1.8 KB)
--- api/srfi18/src/Posix/cthread.c	2016-12-07 14:20:46.000000000 +0100
+++ api/srfi18/src/Posix/cthread.c	2017-01-03 15:09:50.682744744 +0100
@@ -83,6 +83,7 @@
 /*---------------------------------------------------------------------*/
 void
 srfi18_thread_start( srfi18thread_t thread, obj_t bglthread, bool_t dt ) {
+   int createret;
    pthread_attr_t a;
 
    pthread_attr_init( &a );
@@ -91,8 +92,8 @@
 
    bglpth_thread_env_create( thread, bglthread );
    
-   if( pthread_create( &(thread->bglpthread.pthread), &a, srfi18_thread_run, thread ) )
+   if( createret = pthread_create( &(thread->bglpthread.pthread), &a, srfi18_thread_run, thread ) )
       FAILURE( string_to_bstring( "thread-start!" ),
 	       string_to_bstring( "Cannot start thread" ),
-	       string_to_bstring( strerror( errno ) ) );
+	       string_to_bstring( strerror( createret ) ) );
 }
--- api/pthread/src/Posix/bglpthread.c	2016-12-07 14:20:46.000000000 +0100
+++ api/pthread/src/Posix/bglpthread.c	2017-01-03 15:08:53.090747326 +0100
@@ -217,6 +217,7 @@
 /*---------------------------------------------------------------------*/
 void
 bglpth_thread_start( bglpthread_t thread, obj_t bglthread, bool_t dt ) {
+   int createret;
    pthread_attr_t a;
 
    pthread_attr_init( &a );
@@ -238,10 +239,10 @@
 
    bglpth_thread_env_create( thread, bglthread );
    
-   if( pthread_create( &(thread->pthread), &a, bglpth_thread_run, thread ) )
+   if( createret = pthread_create( &(thread->pthread), &a, bglpth_thread_run, thread ) )
       FAILURE( string_to_bstring( "thread-start!" ),
 	       string_to_bstring( "Cannot start thread" ),
-	       string_to_bstring( strerror( errno ) ) );
+	       string_to_bstring( strerror( createret ) ) );
 }
 
 /*---------------------------------------------------------------------*/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.