I think this applies to Solaris and other *NIX variants, including
Linux. I don't have easy access to other platforms to check how errno is
defined there. Perhaps the Makefiles should only define _REENTRANT for
some build environments.
It looks like other library development projects have run into similar
issues (see http://mail.gnome.org/archives/xml/2001-June/msg00047.html
and http://curl.haxx.se/mail/lib-2004-10/0260.html).
I think there should a configure option like --enable-threadsafe that
defines the appropriate compilation options to build the library for
multi-threaded use. It would probably add -mt and -D_REENTRANT to
CPPFLAGS in the Makefiles, at least for some build environments.
Daniel, does libcurl provide a configurable option to build for
multi-threaded use? If so, perhaps it should be done the same way in
libssh2.
-- Troy
-----Original Message-----
From: libssh2-devel-bounces_at_lists.sourceforge.net
[mailto:libssh2-devel-bounces_at_lists.sourceforge.net] On Behalf Of James
Housley
Sent: Thursday, June 07, 2007 7:43 PM
To: libssh2-devel_at_lists.sourceforge.net
Subject: Re: [libssh2] Does sftp work in a multi-threaded program?
(PROBLEMSOLVED)
On Jun 7, 2007, at 3:15 PM, Gutjahr, Troy wrote:
> I tried my test program with libssh2-0.14. It works. libssh2_sftp_init
> succeeds in both the main thread and a second thread.
>
> I suspect that the problem has been exposed by the recently added
> non-blocking code in libssh2-0.15.
>
> To try to diagnose the problem, I built my test program with gcc 3.2
> instead of the Sun Studio 11 compiler and I used gdb to step through
> the
> libssh2-0.15-20070605 code. The problem occurs at line 308 of
> transport.c. The recv function is returning -1 but errno is 0, which
> should be impossible.
>
> The problem is that the global variable errno should not be accessed
> directly when multi-threaded. We should add -D_REENTRANT to CPPFLAGS
> in the Makefiles. That causes errno to be redefined in errno.h to be
> (*(___errno())), which is threadsafe.
>
> I made this change in my Makefiles and rebuilt the library. Now my
> application is able to use sftp in different threads.
>
> I'm not familiar with the intricacies of the configure script. I think
> this change should be made there, so that the configured Makefiles
> have the correct definition of CPPFLAGS.
>
> Would someone please make this change?
Will have to be someone with more knowledge then me, all the systems I
have access to always define errno as:
extern int * __error();
#define errno (* __error())
Jim
-- /"\ ASCII Ribbon Campaign . \ / - NO HTML/RTF in e-mail . X - NO Word docs in e-mail . / \ ----------------------------------------------------------------- jeh@FreeBSD.org http://www.FreeBSD.org The Power to Serve jim@TheHousleys.Net http://www.TheHousleys.net --------------------------------------------------------------------- Fortune Not Found: Abort, Retry, Ignore? ------------------------------------------------------------------------ - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ libssh2-devel mailing list libssh2-devel_at_lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libssh2-devel ============================================================ The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any reproduction, dissemination or distribution of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. Tellabs ============================================================ ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ libssh2-devel mailing list libssh2-devel_at_lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libssh2-develReceived on 2007-06-08