Re: pthreads and standard C library calls and maybe magic Xcode switches
Re: pthreads and standard C library calls and maybe magic Xcode switches
- Subject: Re: pthreads and standard C library calls and maybe magic Xcode switches
- From: Greg Guerin <email@hidden>
- Date: Tue, 21 Aug 2007 14:55:10 -0700
Cem Karan wrote:
>Better yet, is there a magic switch somewhere that I can throw
>that will tell Xcode to be aware that my code is threaded, and that
>therefore all the caches must be kept fully coherent between the
>cores/processors?
Xcode should already be aware your code is threaded (or could be). It's
compiling for a multi-threaded multi-core OS. If the standard libs aren't
thread-aware or multi-core aware, your program will be pretty much DOA.
There should be hardware in the cores/processors that keeps CPU caches
coherent. That's why CPU's (or their memory controllers) have
cache-coherency protocols. E.g.:
<http://en.wikipedia.org/wiki/MESI_protocol>
The one place where the hardware protocol won't work is when the software
itself caches memory values in registers, such as moving a pointer from a
memory variable or arg into a register, and then using the register value
for a more or less extended period of time.
The 'volatile' keyword eliminates that kind of register-based caching, but
you should not have to worry about functions like memcpy(), because it's
either re-entrant or it isn't, and caching args in registers is irrelevant
to that aspect of its correctness. For functions that DO have to worry
about register caching, they should be written to use 'volatile'
internally, so again you don't worry about it.
In short, the OS-provided library functions should take care of themselves
(i.e. be properly written). You only have to worry about functions you
write, or ones you use to replace OS-provided functions.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden