JavaRush
AI Academy
new
Promotion
Learning
Courses
Tasks
Quizzes
Games
Help
Schedule of nudges
Internship
Community
Users
Forum
Chat
Articles
Activities
Reviews
Subscriptions
Light theme

Lectures

  • Reviews
  • About us
  • CS50
Start
Start learning
Start learning
  • My progress
  • Courses
  • Quest map
  • Lectures
  • sync.Mutex: critical sections and the Lock → Unlock discipline

    Go SELF
    68 level,0 lecture
    We break down why you need sync.Mutex in concurrent Go code, where a data race starts, how to выделать critical sections, and how to follow the Lock() → Unlock() discipline. We will show the defer idiom for releasing a lock, discuss its limits (especially inside loops), build a thread-safe TaskStore (methods Add, Get, ListSnapshot), and analyze what deadlock scenarios look like and the typical mistakes.
    Open
  • sync.RWMutex — when it helps and when it hurts

    Go SELF
    68 level,1 lecture
    We break down how sync . RWMutex works in Go: how read-lock and write-lock differ, how to correctly protect map and slices from races, why it is dangerous to expose “live” collections (aliasing), when RWMutex actually speeds up frequent short reads, and when it adds overhead and latency. We also discuss the forbidden “upgrade” RLock() → Lock(), the double-check pattern, and common mistakes that lead to a data race or hangs.
    Open
  • sync/atomic — counter/flag and when it is justified

    Go SELF
    68 level,2 lecture
    We break down when it actually makes sense to use sync/atomic in Go: for independent counters and flags ( atomic.Int64, atomic.Bool), operations Add/ Load/ Store and CAS ( CompareAndSwap, “first wins”). Using TaskStore as an example, we show how to combine atomics with sync.RWMutex, and we also draw clear boundaries of applicability: where you need a Mutex for invariants and which mistakes most often break concurrent code.
    Open
  • sync.Once — safe one-time initialization

    Go SELF
    68 level,3 lecture
    We break down how, in concurrent Go code, to guarantee “initialize exactly once” using sync.Once: why the naive if + nil check leads to data races, how the Once.Do contract works, why Once must not be copied after first use, why recursive calls to Do are dangerous (deadlock), and how correct memory visibility relates to the Go memory model (“synchronizes before”). We reinforce everything with examples: lazy initialization of a map, keeping Once inside a struct, and storing the result/error because Do returns nothing.
    Open
  • What exactly are we protecting — state in app, storage, and cache

    Go SELF
    68 level,4 lecture
    We break down what kinds of mutable state exist in a Go application at different layers ( app, storage, cache), who owns the data, and which synchronization primitives to choose: Mutex for invariants, RWMutex for frequent reads, atomic for simple counters. With examples, we cover operation deduplication, in-memory storage, file writes, a cache wrapper with invalidation, and common mistakes (a global lock, long critical sections, and leaking internal structures to the outside).
    Open
Learn
  • Registration
  • Java course
  • Help with tasks
  • Pricing
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Activities
Company
  • About us
  • Contacts
  • Reviews
  • FAQ
  • Support
JavaRushJavaRush — is an interactive online course for learning Java programming from scratch. It contains 1200 practical tasks with one-click solution checking, the necessary minimum of theory on Java basics, and motivating features that help you complete the course: games, quizzes, interesting projects and articles on effective learning and the career of a Java developer.
Follow us
Язык интерфейса
Русский
English
Українська
"Programmers are not born" © 2026 JavaRush
MastercardVisa
"Programmers are not born" © 2026 JavaRush