Imagine you are utilizing Parallelism in a multi-core system.
Is it not completely possible that the same instructions may be executed simultaneously?
Take the following code:
int i = 0;
if( blockingCondition )
{
lock( objLock )
{
i++;
}
}
In my head, it seems that it is very possible on a system with multiple cores and parallelism that the blockingCondition could be checked at precisely the same moment, leading to the lock being attempted at the same moment, and so on...Is this true?
If so, how can you ensure synchronization across processors?
Also, does the .net TPL handle this type of synchronization? What about other languages?
EDIT Please note that this is not about threads, but Tasks and Parallel-Processisng.
EDIT 2 OK, thanks for the information everyone. So is it true that the OS will ensure that writing to memory is serialized, ensuring multi-core synchronization via volatile reads?