From owner-freebsd-hackers Mon Mar 15 14:26:39 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from oracle.dsuper.net (oracle.dsuper.net [205.205.255.1]) by hub.freebsd.org (Postfix) with ESMTP id 5B96A1526B for ; Mon, 15 Mar 1999 14:24:10 -0800 (PST) (envelope-from bmilekic@dsuper.net) Received: from jehovah (jehovah.technokratis.com [207.139.115.248]) by oracle.dsuper.net (Delphi 1.3/8.6.9) with SMTP id RAA25669; Mon, 15 Mar 1999 17:23:26 -0500 (EST) Message-ID: <005001be6f33$0f817470$0100000a@jehovah.technokratis.com> Reply-To: "Bosko Milekic" From: "Bosko Milekic" To: "FreeBsd" Cc: Subject: Re: thread and socket Date: Mon, 15 Mar 1999 17:27:49 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG You'll have to excuse my previous post. (whoopsy). :-) The reason you may be having this problem may be related to the fact that the global integer 'errno' that you are checking is not really 'thread-safe.' The copy of the code you are running contains only one global int errno, and when you check for it in the thread (e.g. when it's re-enterant), there is a problem. Stevens proposes saving the initial value of 'errno' before going elsewhere. You would declare another int (e.g. saveerrno) and do something like: saveerrno = errno; (and then go ahead with your function(s) in the thread) I gave you as an example the global value 'errno,' but you should check any functions you call in threads and make sure that they are thread-safe... I am not very proficient with threads, but I can see an alternative to your problem (if you are still having it). Instead of having your thread go non-blocking, just allow it to block, the kernel will just run some other thread until their is data ready for the blocked function... in your main copy of the code, you can set your own timer which, after expiry, checks whether or not a global buffer has been filled (the buffer would only be filled if recvfrom() returns), and if it hasn't, it can kill the thread, knowing that there was no data to be read... Regards, Bosko M. ____________________________________________________________________________ Bosko Milekic bmilekic@oracle.dsuper.net http://www.dsuper.net/~bmilekic/ Delphi SuperNet +1.888.787.3768 http://www.supernet.ca/ -----Original Message----- From: FreeBsd To: Bosko Milekic Cc: freebsd-hackers@FreeBSD.ORG Date: Monday, March 15, 1999 4:19 AM Subject: Re: thread and socket :in multithreaded app is recvfrom only waiting for data, but cannot finish :with EAGAIN error, when I set SO_RCVTIMEO. I need stop recv function after :timeout. in the non threaded version rcv is finish after timeout (no data :is received) , but in multi threaded ver doesn't stop and still is waiting :for data. any data is not comming and ercvfrom is still wiating. WHY????? :thanks. :honza : : :On Sun, 14 Mar 1999, Bosko Milekic wrote: : :> :> I've had a little trouble understanding you... :-) :> :> Here's an excerpt from the man page, though... if this isn't what you were :> looking for, please clarify a bit... :> :> --snip-- :> In the non-threaded library getsockopt() is implemented as the :> getsockopt syscall. :> :> In the threaded library, the getsockopt syscall is assembled to _thread_sys_getsockopt() :> and getsockopt() is implemented as a function which locks s for read and :> write, then calls _thread_sys_getsockopt(). :> Before returning, getsockopt() unlocks s. :> --snip-- :> :> Regards, :> Bosko. :> :> -- :> Bosko Milekic http://www.supernet.ca/~bmilekic/ :> Delphi SuperNet voice: (+1) 514 281-7500 fax: (+1) 514 281-6599 :> PGP Key available upon request. :> : To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message