In message <>, Pascal J.
Bourguignon <> writes
>Bob from Chesham Bois <> writes:
>
>> [ Earlier incomplete post sent by mistake - sorry! ]
>>
>> Can using "register make C++ code non-reentrant? For example:
>>
>> int myIncrement ( int myinput)
>> {
>> register int newint = myinput;
>> newint++;
>> return newint;
>> }
>>
>> If two threads enter this function concurrently, will they share the
>> same hardware register for "newint"? In which case the second thread
>> may overwrite the value that the first thread stored in the register.
>> Is this a danger? Whereas if the "register" declaration is not used,
>> there is no danger, because each thread has its own "newint" on its
>> stack.
>
>No. Either the two threads are running in different cores, in which
>case each core has its own set of registers, or they're running in the
>same core, in which case they don't run at the same time, and the OS
>takes care of saving and restoring the registers so it looks like each
>thread has its own registers.
>
In any case, register is little more than a hint, so the compiler
probably ignores it.
--
Richard Herring
|