Skip to Content
Go: Building Web Applications
book

Go: Building Web Applications

by Nathan Kozyra, Mat Ryer
August 2016
Beginner to intermediate
665 pages
14h 11m
English
Packt Publishing
Content preview from Go: Building Web Applications

Using sync and mutexes to lock data

One issue that you may have run into with the preceding examples is the notion of atomic data. After all, if you deal with variables and structures across multiple goroutines, and possibly processors, how do you ensure that your data is safe across them? If these processes run in parallel, coordinating data access can sometimes be problematic.

Go provides a bevy of tools in its sync package to handle these types of problems. How elegantly you approach them depends heavily on your approach, but you should never have to reinvent the wheel in this realm.

We've already looked at the WaitGroup struct, which provides a simple method to tell the main thread to pause until the next notification that says a waiting process ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Full Stack Development with Go

Hands-On Full Stack Development with Go

Mina Andrawos

Publisher Resources

ISBN: 9781787123496