0

The shared memory is used by 2 process with shm_open and mmap.

The shared memory is an 16-bit array.

The application is run in an arm 32bit embedded Linux.

My understanding is since accessing each element is independent and atomic, to protect the sharing memory with complex mutex is unnecessary inefficient.

  • 1
    Accessing individual bits is never atomic, unless you're on MCS51 or something. :) On most architectures, accessing individual bytes is never atomic either, unless you take precautions (like special opcodes and such). – oakad May 22 '14 at 02:15
  • A 16 bit array? So, two bytes? Of shared memory? – user703016 May 22 '14 at 02:20
  • If you mean the array has 16-bit elements, a 16 bit write itself might be atomic, but most operations you might want to do like `arr[123]++` or "claim the first empty slot in this shared table" are not, because behind the scenes they involve at least a read and a write, and you don't know what happens in between. (See, for instance, http://stackoverflow.com/questions/10503737/is-increment-an-integer-atomic-in-x86) – twotwotwo May 22 '14 at 02:54
  • Thanks for the comments. Yes it's an array with 16-bit long integers(for example, uint16_t type). the only operation is read and write each element, i.e. uint16_t get_value(uint16_t index){if(index >= Max_len) assert(OUT_OF_RANGE); else return shared_memory[index]) ;} void set_value(uint16_t index, uint16_t value){if(index >= Max_len) assert(OUT_OF_RANGE); else shared_memory[index] = value;} accessing the shared memory is frequent. this is why I ask this question for the sake of efficiency. – user3639690 Jun 07 '14 at 01:03

0 Answers0