<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 06 Feb 2013, at 23:16, Ewald wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">Concerning the locking mechanism, you can uses mutex(en/es/ii) or you<br>can do this by a busy waiting loop with an integer (of course there are<br>other possibilities). To elaborate on the latter a bit more:<br><br>* TLockType = Integer;<br>* Initialization: `Lock:= 0;`<br>* Lock & unlock:<br><br>===> Code Begin <===<br><br>Procedure WaitLockVar(var aLock: Integer);<br>Begin<br> Repeat<br> Until InterLockedCompareExchange(aLock, 1, 0) = 0;<br>End;<br><br>Procedure UnlockVar(var aLock: Integer);<br>Begin<br> InterlockedExchange(aLock, 0);<br>End;<br><br>===> Code End <===<br><br>This last code is tested and works.<br></span></span></blockquote></div><div><br></div><div>It only works on some platforms (and even there it may change depending on which exact processor you are using). InterlockedExchange does not guarantee any kind of memory barrier, and hence you will get occasional data races on platforms with weakly consistent memory models. You have to add memory barriers.</div><div><br></div><div><br></div><div>Jonas</div></body></html>