Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
No need for Semaphore when data size is <= 32 bit ?
« on: May 01, 2006, 01:25:49 AM »
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). ?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Re: No need for Semaphore when data size is <= 32 bit ?
« Reply #1 on: May 01, 2006, 05:25:14 PM »
I actually forgot to mention that the thread/process involved only does a very tiny instruction with the variable, that most likely corresponds to one instruction in assembler.

@Piru
"Just reading or writing the value doesn't give anything useful, or at least I can't think of any use for that."

Raising a counter;) But maybe this wouln't be atomic in PPC ?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Re: No need for Semaphore when data size is <= 32 bit ?
« Reply #2 on: May 01, 2006, 06:05:42 PM »
Pah, 68k rules:)
Ok I'll use a damn Semaphore for the thing... :-x
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Re: No need for Semaphore when data size is <= 32 bit ?
« Reply #3 on: May 05, 2006, 01:29:48 AM »
I'm now really getting into a part of my code that uses this. I had some more thought into it. There are 2 reasons I can remember to use a semaphore: protect access from another task and, more serious (cause it can lead to a crash or a program malfunction), data integrity. Even if raising a counter is not atomic in PPC, I'm sure the write cannot be interrupted (you don't get a 32 bit counter's read with half the current and half the previous value), so data integrity is not a problem here.
So to avoid using data that is not uptodate I decided to not use a semaphore, but a software interrupt in the task that's using it. The timer.device is about the only one that can be used with an interrupt  from what I've read on the RKM's libraries, and that's the one I'm receiving messages from, after wich some actions are take and counter is raised, so it's all good.

Any caution/problems/advice with this solution, or it's just brilliant ? 8-)
\\"We made Amiga, they {bleep}ed it up\\"