Mail Archives: cygwin/2001/06/26/08:12:26
------=_NextPart_000_00A8_01C0FE8D.12F25890
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
----- Original Message -----
From: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>
>
> ----- Original Message -----
> From: "Greg Smith" <gsmith AT nc DOT rr DOT com>
> To: "Cygwin General MailList" <cygwin AT cygwin DOT com>
> Sent: Tuesday, June 26, 2001 12:21 PM
> Subject: Re: pthreads works, sorta
>
>
> > Robert Collins wrote:
> > > >
> > > > My (heavily threaded) application runs approximately 100x
> > > > slower than under linux and proceeds to the point where the
> > > > program thrashes because it is calling pthreads functions
> > > > faster than the pthreads implementation can deliver (we're
> > > > talking _mutex_lock/unlock and _cond_wait/signal here).
> > >
> > > Condition variables we can't do much about here, other than trying
> to
> > > get down to the metal and rewrite em without OS support. I'm not
> keen to
> > > try that, for what I hope are obvious reasons.
> >
> > True.
> >
>
> I've just reviewed my reading, and it doesn't look as though critical
> sections are going to be _much_ faster.
>
> --> Greg, do you know that your issue is thread syncronisation
> performance, or performance of I/O or other posix calls in between ?
You
> program shouldn't crash unless it manages to deadlock or trigger a
> race... certainly the pthread calls cannot happen except when your
> threads are active and have got cpu :].
>
> How many concurrent threads and mutexs and cond variables are we
talking
> here?
>
Also, if you use pthread_cond_timedwait, you might like to try the
attached patch, it fixes a misinterpretation of the time parameter in
the spec. That slight reading error would cause huge (potentially years
long!) delays. Threads would appear to hang... etc.
Changelog:
Tue Jun 26 22:10:00 2001 Robert Collins rbtcollins AT hotmail DOT com
* thread.cc (pthread_cond::TimedWait): Check for WAIT_TIMEOUT as
well as WAIT_ABANDONED.
(__pthread_cond_timedwait): Calculate a relative wait from the
abstime parameter.
Rob
------=_NextPart_000_00A8_01C0FE8D.12F25890
Content-Type: application/octet-stream;
name="condtimedwaitisabsolute.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="condtimedwaitisabsolute.patch"
Index: thread.cc=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/src/src/winsup/cygwin/thread.cc,v=0A=
retrieving revision 1.36=0A=
diff -u -p -r1.36 thread.cc=0A=
--- thread.cc 2001/06/24 22:26:53 1.36=0A=
+++ thread.cc 2001/06/26 12:04:49=0A=
@@ -44,6 +44,7 @@ details. */=0A=
#include "security.h"=0A=
#include <semaphore.h>=0A=
#include <stdio.h>=0A=
+#include <sys/timeb.h>=0A=
=0A=
extern int threadsafe;=0A=
=0A=
@@ -472,6 +473,7 @@ pthread_cond::TimedWait (DWORD dwMillise=0A=
case WAIT_FAILED:=0A=
return 0; /* POSIX doesn't allow errors after we modify the =
mutex state */=0A=
case WAIT_ABANDONED:=0A=
+ case WAIT_TIMEOUT:=0A=
return ETIMEDOUT;=0A=
case WAIT_OBJECT_0:=0A=
return 0; /* we have been signaled */=0A=
@@ -1654,7 +1656,14 @@ __pthread_cond_timedwait (pthread_cond_t=0A=
return EINVAL;=0A=
if (!verifyable_object_isvalid (*cond, PTHREAD_COND_MAGIC))=0A=
return EINVAL;=0A=
+ struct timeb currSysTime;=0A=
+ long waitlength;=0A=
+ ftime(&currSysTime);=0A=
+ waitlength =3D (abstime->tv_sec - currSysTime.time) * 1000;=0A=
+ if (waitlength < 0)=0A=
+ return ETIMEDOUT;=0A=
=0A=
+ /* if the cond variable is blocked, then the above timer test maybe =
wrong. *shrug* */=0A=
if (pthread_mutex_lock (&(*cond)->cond_access))=0A=
system_printf ("Failed to lock condition variable access mutex, =
this %0p\n", *cond);=0A=
=0A=
@@ -1671,7 +1680,7 @@ __pthread_cond_timedwait (pthread_cond_t=0A=
InterlockedIncrement (&((*themutex)->condwaits));=0A=
if (pthread_mutex_unlock (&(*cond)->cond_access))=0A=
system_printf ("Failed to unlock condition variable access mutex, =
this %0p\n", *cond);=0A=
- rv =3D (*cond)->TimedWait (abstime->tv_sec * 1000);=0A=
+ rv =3D (*cond)->TimedWait (waitlength);=0A=
(*cond)->mutex->Lock ();=0A=
if (pthread_mutex_lock (&(*cond)->cond_access))=0A=
system_printf ("Failed to lock condition variable access mutex, =
this %0p\n", *cond);=0A=
------=_NextPart_000_00A8_01C0FE8D.12F25890
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_NextPart_000_00A8_01C0FE8D.12F25890--
- Raw text -