views:

33

answers:

2

Is Mutex required on 1 byte shared resource? If not then why not? Consider I am using normal desktop PC pentium IV , 32 bit. Will condition change if use core 2 duo?

+2  A: 

It depends what you are going to do with it, but if you have multiple writers, implemented in C or C++, then yes you need a mutex - the size of the resource is not the issue.

anon
Yes there are multiple writes and reads.
alam
Just to clear my doubts: If CPU is Single processor then while reading single byte (or word on 32 bit machine) if interrupt happens will it context switch after reading/writing a complete word or conext switch happen immediately? In short how many CPU cycles are required for reading/writing complete word.
alam
@alam It doesn't matter how many clock cycles it takes - to update a value, the compiler can emit code that basically does a read, a change and a write (i.e. at least three machine instructions) , and without a mutex a switch to another thread can take place after any of them..
anon
A: 

CPU doesn't matter as the task scheduler is free to interrupt a thread at any time. Size doesn't matter. If it's shared then you need some method of locking.

Donnie