help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Determining if the GLPK library is compiled to be reentr


From: Heinrich Schuchardt
Subject: Re: [Help-glpk] Determining if the GLPK library is compiled to be reentrant.
Date: Sat, 14 Jan 2017 00:16:46 +0100

Using pthread does not imply that GLPK is used in multiple threads.

Not using pthread does not imply that the application is single threaded. You 
could call the Linux clone syscall directly though I doubt that in this case 
the thread local memory is available at all.

On Windows pthread is not used.

The dll with your example code can only be linked if glp_threads is a static 
variable in the dll.

Best regards

Heinrich Schuchardt

Am 13.01.17 um 23:21 schrieb Reginald Beardsley

> I would like to second Heinrich's suggestion and extend it to report all 
> compile time options if glpsol is invoked with "-v".
> 
> I'm not a fan of threads and have not used them, so the following is a 
> speculation, but I think it might help address the issue.  It may well be 
> functionally equivalent to what Heinrich has proposed.  But as I read what he 
> has proposed someone *could* write a program that failed to test that the 
> library was thread safe.  I think this might catch that.
> 
> In glpk.h add:
> 
> #ifdef _PTHREAD_H
> 
> int glpk_threads = 1;
> 
> #else
> 
> int glpk_threads = 0;
> 
> #endif
> 
> in glp_create_prob() add :
> 
> #ifndef _PTHREAD_H
> 
>    if( glpk_threads ==1 ){
>       fprintf( stderr, "libglpk not thread safe!" );
>       exit( -1)
>    }
> 
> #endif
> 
> Unless I've buggered up the logic, if someone writes a main.c that includes 
> pthread.h  and then links it with a libglpk that is not compiled to be thread 
> safe it will throw an error that explains the problem.  
> 
> If the main program does not use threads and the library is not thread safe 
> then glpk_threads == 0.  If the library is threadsafe but the main does not 
> use threads, the code is not compiled and glpk_threads is not tested.
> 
> Hopefully I've gotten the general idea across even if it's not quite right.  
> As remarked, I don't like threads.  If I wanted threads I'd use MS-DOS  or 
> similar without the benefit of protected memory.
> 
> 
> Reg
> --------------------------------------------
> On Fri, 1/13/17, Heinrich Schuchardt <address@hidden> wrote:
> 
>  Subject: [Help-glpk] Determining if the GLPK library is compiled to be 
> reentrant.
>  To: "Andrew Makhorin" <address@hidden>, "address@hidden" <address@hidden>
>  Date: Friday, January 13, 2017, 1:31 PM
>  
>  Hello Andrew,
>  
>  a program that uses a GLPK library which is not compiled
>  with thread
>  local storage may fail fatally when run with multiple
>  threads.
>  
>  I hence suggest to add a function that allows to determine
>  if GLPK was
>  compiled to be reentrant. We could use the same function to
>  return other
>  features too.
>  
>  typedef struct {
>     char * option;
>     char * value;
>  } glp_build_options;
>  
>  #include "config.h"
>  
>  static glp_build_options build_options[] = {
>        {"TLS",
>  #ifdef TLS
>        "available" },
>  #else
>        NULL },
>  #endif
>        {"ODBC_DLNAME",
>  #ifdef ODBC_DLNAME
>        ODBC_DLNAME},
>  #else
>        NULL},
>  #endif
>        {NULL, NULL}
>     };
>  
>  glp_build_options *glp_version_ex() {
>     return build_options;
>  }
>  
>  Best regards
>  
>  Heinrich Schuchardt
>  
>  _______________________________________________
>  Help-glpk mailing list
>  address@hidden
>  https://lists.gnu.org/mailman/listinfo/help-glpk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]