[unixODBC-dev] A multi-thread contention issue when using lt_dlinit function

Nick Gorham nick at lurcher.org
Thu Apr 11 07:31:47 BST 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20130411/dfab3712/attachment-0001.html>


More information about the unixODBC-dev mailing list