Iostream deadlock...

Fons Rademakers Fons.Rademakers@cern.ch
Wed Feb 23 11:04:00 GMT 2000


Yes, I saw already the weak linking pragmas in libio, but it was nowhere
described that after loading the "real" symbols would not be linked in place
of the dummies. I understand that -lpthread always works, but I've a
modular application framework which is basically only linked with -ldl
and loads dynamically the modules it needs.

Cheers, Fons.



"Martin v. Loewis" wrote:
> 
> > I hope you now will do something with the problem.
> 
> Thanks again for your bug report. This is not a bug in gcc, and
> neither in glibc. Loading libpthread.so via dlopen does not work; you
> need to link it statically. A corrected version of your program looks
> like this:
> 
> //------------- tb.cxx ----------------
> // On linux compile with: g++ -o tb tb.cxx -ldl -lpthread
> #include <iostream.h>
> #include <fstream.h>
> #include <dlfcn.h>
> 
> int main()
> {
>    const char *fname = "tb.cxx";
>    int c;
>    ifstream file0(fname);
>    //c = file0.get();    // call get() before loading pthread
>                          // and the problem disappears
>    ifstream file1(fname);
>    if (!file1) {
>       cerr << "Cannot open file " << fname << endl;
>       return 1;
>    }
> 
>    c = file1.get();  // remove first character   <-- deadlock here
> 
>    char line[256];
> 
>    file1 >> ws;   // eat whitespace
>    file1 >> line;
> 
>    cout << "First token is: " << line << endl;
> 
>    return 0;
> }
> 
> That works fine for me.
> 
> In case you wonder why dynamic loading of libpthread does not work:
> The C library provides weak symbols of the libpthread functions, which
> are used in case libpthread is not loaded, and which do nothing. If
> you are loading it dynamically, then it uses the weak versions in some
> calls, and the truly multithreaded versions of some other
> functions. That cannot work.
> 
> Regards,
> Martin

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910


More information about the Gcc mailing list