Article View: borland.public.cppbuilder.nativeapi
Article #6303Re: threads memory access
From: Heinrich Wolf
Date: Tue, 24 May 2005 18:17
Date: Tue, 24 May 2005 18:17
7 lines
1322 bytes
1322 bytes
The boolean lock is not safe with a multiprocessor or hyper threading machine. If you do not want a critical section, go this way: You need to do an atomic increment and decrement. So replace the boolean variable by a word or byte with startup value 0. When accessing the structure, increment the variable and then check, if it is 1. If you read 1, continue working on the data and finally decrement the variable. If you read more than 1, then there is a second access. Do not touch the data and just decrement the variable.
Technical Details
Message-ID:
<3fh9ejF7ss8lU1@individual.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mailReferences:
<428e4b3f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f662da50ec5f6f69 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Heinrich Wolf" <invalid@invalid.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: threads memory access Date: Tue, 24 May 2005 20:17:57 +0200 Lines: 9 Message-ID: <3fh9ejF7ss8lU1@individual.net> References: <428e4b3f$1@newsgroups.borland.com> X-Trace: individual.net 3XqISSPeYrLikSh5TyTVIA8ApdDgr+2h8oueHv795ThdwnUO9A X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-RFC2646: Format=Flowed; Response