From: Piranha on
On 21 Apr., 17:04, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote:
> Piranha wrote:
> > I got the point of making things complicated, have to check out the
> > critical section thing, but for now all I´m concerned about is this
> > lag, where I´m trying to rule out possible causes.
>
> > So let me get that straight .....
> > It could be done easier, but my solution should work?
>
> A definite "maybe", but with a tendency to "works". The problem is that you
> show too little code. Also, if your real code also leaves out the error
> handling completely, trouble ensues. Another thing to keep in mind is that
> this mutex is indeed system-global, so two instances of your app will
> interfere with each other.
>
> > No matter how many threads are waiting for the mutex, only one of them
> > gets the access and the system has no problems that could result in a
> > lag in case several threads are waiting?
>
> > Or in short: I can rule out this one and have to search my lag
> > elsewhere?
>
> I would look somewhere else for the lag. I would however make doubly sure
> that the multithreaded stuff is correct, as this will give you the nastiest
> kind of bugs when only it's only almost correct.
>
> Good luck!
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Thanks, I´ll keep that in mind.
From: David Schwartz on
On Apr 21, 7:27 am, Piranha <eu_pira...(a)gmx.net> wrote:

> Or in short: I can rule out this one and have to search my lag
> elsewhere?

I would suggest you instrument all your calls to acquire the mutex. If
you want to be fancy, you can make your mutex acquisition code work
like this:

1) Note the time.
2) Acquire the mutex.
3) Note the time.
4) If the time elapsed between steps 1 and 3 is more than some
threshold, say 500ms, log the file name and line number of the last
thread to hold the mutex.
5) Mark yourself as the file name and line number holding the mutex.

That way, if it's not the mutex, you'll know. And if it is the mutex,
you'll know the file name and line number where the mutex was last
held (presumably for too long).

DS