Welcome, Guest. Please login or register.

Author Topic: No need for Semaphore when data size is <= 32 bit ?  (Read 3810 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: No need for Semaphore when data size is <= 32 bit ?
« on: May 01, 2006, 10:17:49 AM »
Quote

Jose wrote:
Would I be correct in assuming that all data that is smaller than 32 bits doesn't actually need a Semaphore when shared between tasks and/or processes cause it's allways valid (the CPU reads/writes to it at once so there's no way a task/process will be interrupted in the middle). ?


How can you guarentee the read write operation will not be interrupted? It could be preempted to switch out before it gets the chance to write the modified data back. Your operation would need to be atomic, as Piru says. I am not sure off the top of my head but IIRC, only instructions like TAS etc have an atomic read/write cycle.
int p; // A