Is bool thread safe?

3,082 views
Skip to first unread message

tomwilde

unread,
Oct 3, 2012, 1:04:38 PM10/3/12
to golan...@googlegroups.com
Do I need a mutex for a bool?

Daniel Morsing

unread,
Oct 3, 2012, 1:39:00 PM10/3/12
to tomwilde, golan...@googlegroups.com
On Wed, Oct 3, 2012 at 7:04 PM, tomwilde <sedevel...@gmail.com> wrote:
> Do I need a mutex for a bool?
>
> --
>
>

Yes.

Or send it on a channel.

bryanturley

unread,
Oct 3, 2012, 1:55:21 PM10/3/12
to golan...@googlegroups.com
Or just use a uint32 and pretend it is a bool with
http://golang.org/pkg/sync/atomic/
Probably faster than a mutex or a channel for just a single (pseudo) bool.

If the package documentation confuses you read this
http://en.wikipedia.org/wiki/Compare-and-swap

Dave Cheney

unread,
Oct 3, 2012, 9:04:19 PM10/3/12
to bryanturley, golan...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages