Re: A multi-thread contention issue when using lt_dlinit function

Nick Gorham <[email protected]> Thu, 11 Apr 2013 07:31:47 +0100
Newsgroups gmane.comp.db.unixodbc.devel
Message-ID <[email protected]>
On 11/04/13 07:24, xiaonan wrote:
>  Hi, Nick:
>
>     Sorry for interrupting you again!
>
>     Because libltdl functions are not thread-safe 
> (http://www.gnu.org/software/libtool/manual/html_node/Thread-Safety-in-libltdl.html), 
> we should add lock before using them.
>
>     In __connect_part_one function:
>     {
>         ......
>         /*
>          * initialize libtool
>          */
>
>         lt_dlinit();
>         ......
>
>         if ( !(connection -> dl_handle = odbc_dlopen( driver_lib )))
>        ! ; {
>            ......
>         }
>      }
>
>      int lt_dlinit (void)
>      {
>          ......
>          if (++initialized == 1)
>          {
>             ......
>          }
>
>      }
>
>      In multi-thread environment, there will be a scenario: Thread 1 
> calls lt_dlinit(), and the initialized's value is 1. Then Thread 2 
> calls lt_dlinit(), and the initialized's value is changed to 2. Thread 
> 2 thinks the initializtion is OK, so it will continue executing and 
> calls odbc_dlopen(). But in fact, the initialization isn't done! So 
> odbc_dlopen() will return NU! LL.
>
>      So I think we should add lock before using lt_dlinit(), such as:
>
>      mutex_lib_entry();
>      lt_dlinit();
>      mutex_lib_exit();

Yes, I see what you are saying, I will look at adding that mutex.

-- 
Nick

_______________________________________________
unixODBC-dev mailing list
[email protected]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev