what is the purpose of atomic_t?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    what is the purpose of atomic_t?

    Can anyone explain

    what is the purpose of atomic_t

    in types.h(linux) I found the definition like this
    Code:
    typedef struct 
    { 
      int counter;
    } atomic_t;
    But I cant understand the purpose of this definition.

    Best Regards,
    johny
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Someone has defined a struct with an int member as atomic_t.

    You can now use atomic_t as a type.

    types.h is a non-ANSI header so I don't know the reason for this.

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      The purpose of atomic_t is to implement a type and a set of functions that can operate on it correctly from different threads without requiring synchronization like mutexes. It is implemented in its own way on a specific platform so that it's guaranteed by implementation.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Thank you for the clarification. I hadn't see atomic_t before not being a Linux guru.

        Comment

        Working...