casper....@sun.com writes: > > >A customer had a small program using pthreads that crashed pretty much at > startup. After verifying the crash on my system, I noticed that the customer > >had not linked the program with libpthread. Adding -lpthread to the linking > > command fixed the problem. > > > >If a program does not link a needed library, shouldn't it fail at link time? > >As it is, the program links and loads, but crashes mysteriously. Why is this > >a good idea? Why are there entry points in /lib/libc.so.1 for pthread > >functions, > > but not the pthread functionality? > > Your customer is not using Solaris 10 or OpenSolaris; on those systems, > there's no longer a specific -lthread or -lpthread. They all live in libc. > > For older releases, he must make sure that he handles all error returns > from pthread* and such.
Just to add a little detail to that: Prior to S10, there were intentional dummy entry points for the pthread* functions in libc. They just returned errors. The reason these existed was to allow developers to write libraries that conditionally used threads: you could have your library call the pthread functions and (if needed) check the result. If the application using the library was linked with threads (and thus MT-aware), you'd get MT behavior because you'd pick up the real functions in the thread library rather than the dummies in libc. If the application was not linked with threads, then you'd get errors from the dummy functions, and you could handle as appropriate. Thus, although it was possible to write an _application_ (rather than a library), and call the pthread entry points without linking libpthread, it would be a very strange thing to do, and it'd just give error returns. As of S10, the pthreads functions are in libc and everything is multithreaded. If you were previously calling those functions and expecting them to fail, they'll stop failing on upgrade. -- James Carlson, Solaris Networking <james.d.carl...@sun.com> Sun Microsystems / 35 Network Drive 71.232W Vox +1 781 442 2084 MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677 _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code