If the two threads are within one core, they can share data through cache, but if they are in separate threads, they have to share data through memory?
@Richard: you are right when you say that two threads in a single core can share data through cache. But if they are in separate cores (I'm assuming you meant "cores" instead of "threads" above), then they'll have a copy of that data through their own private caches, which will have a copy in the closest shared cache (L2 or L3). If one of them writes to that data, the copy of that data in the other core's cache will be invalidated through the cache coherency scheme that the processor implements.
@fleventyfive Thanks a lot.
@fleventyfive Which will be responsible for validating the data staleness, OS(software) or the core(hardware)?