[DUG] Threads again
Ross Levis
ross at stationplaylist.com
Wed Jul 18 01:02:42 NZST 2007
Ahh. I thought I had heard of some way of doing this. I actually need to
use InterlockedExchangeAdd as it's not 1 that it is incremented by, but I've
implemented this and it works.
Many thanks,
Ross.
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Myles Penlington
Sent: Tuesday, 17 July 2007 16:35
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Threads again
Yes you need something.
You can use InterlockedIncrement and InterlockedDecrement instead of
Inc/Dec.
Myles.
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Ross Levis
Sent: Tuesday, 17 July 2007 04:02
To: 'NZ Borland Developers Group - Delphi List'
Subject: [DUG] Threads again
I'm trying to avoid using a critical section due to time overhead. In one
thread I have a global integer incrementing roughly every 20 milliseconds
using Inc(x,y). In another thread I have the same integer decreasing using
Dec(x,y) at about the same speed.
Is it critical to have these in a critical section? I've been testing it
here for a few days continuously and it appears to work fine without one.
Even with a dual processor and each thread running on a separate processor,
is it possible for one memory location to be written precisely at the same
time? It doesn't matter which occurs first or in which order.
Cheers,
Ross.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.adventureeducation.co.nz/pipermail/delphi/attachments/20070718/3ad85c98/attachment-0001.html
More information about the Delphi
mailing list