Subj : Re: a thread question To : comp.programming.threads From : Uenal Mutlu Date : Thu May 12 2005 02:01 am "QQ" wrote > Hi I am writing a multithreads program. > I have a variable in the main thread, > can I use it at the child thread? > For example I have a count in main, > when the count reaches 10, I will execute some command at the child > is it OK? Depends on the CPU, but normally if you define the shared integer variable as "volatile" and place it at a CPU word boundary adress then r/w operations will usually be done atomically by the CPU. This is the fastest method, but it depends on the CPU + compiler, though most do it this way. A better and portable method would be to use an atomic counter. A more universal method would be to use a locking mechanism (which usually is based on atomic operations in its inners), for example mutex, criticalsection, or a read-write-lock. .