Mutex VS Atomic in #golang?

  • 4
    I'd go for the mutex because I like mute peope and atomic sounds too radioactive.

    Edit: I'm drunk.
  • 1
    Neither, if possible. I always try to block on channel read in those situations.
  • 0
    @h0ru5 just learning channel btw
    mutex has Rmutex.
    are you talking about that?
  • 1
    @PonySlaystation It was on a text, use mutex from sync, cuz they are safer. But couldn't find anything that will show difference use cases, or difference in work

    thanks btw
  • 2

    very simplified:

    a mutex will ensure that only one concurrent thread/goroutine will execute a piece of code or interact with data protected by the mutex - the next one will wait until the mutex is open.

    an atomic is ensuring that a block of interactions will be done as a whole, e.g. updates of several values, thus if someone reads the data while it is being written, they get a senseful state.

    a channel is sending messages from a to b, avoiding several threads or goroutines handle the same data object or run the same piece of code.
  • 0
    @h0ru5 thanks :D
Your Job Suck?
Get a Better Job
Add Comment