It really depends on how you access the integer:
if you only have one thread doing Inc(x,y), and all other threads just
reading number from that integer, no I don't think you will need to
synchronize the increment. (same for Dec)
but if you have more than one thread making Inc(x,y) on the same x, then
you will need to synchronize. Critical section is too heavy-weighted for
such operation, try use InterlockedIncrement (or InterlockedAdd).
on MP x86 system, you can assert LOCK signal to prevent other processors
from accessing the bus while executing one instruction, by doing so it
ensured "one memory location to be written precisely at the same time".
(You can get more info by reading Intel's "Software Developer's Manuals")
.dlrow eht htiw thgir s'lla ,nevaeh sih ni si doG
From: "Ross Levis" <[EMAIL PROTECTED]>
Reply-To: Borland's Delphi Discussion List <[email protected]>
To: "'Borland's Delphi Discussion List'" <[email protected]>
Subject: Threads again
Date: Tue, 17 Jul 2007 16:04:55 +1200
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.
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_________________________________________________________________
与联机的朋友进行交流,请使用 Live Messenger;
http://get.live.com/messenger/overview
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi