CodeGym
AI Academy
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Race conditions and compound operations on shared state

    Kotlin SELF
    Level 55, Lesson 0
    We break down why races are possible in coroutines too: concurrent execution on Dispatchers . Default, issues with shared mutable state, compound operations like counter ++, and the check-then-act trap. We learn to formulate invariants (for example, tickets >= 0) and identify critical sections, and we also build a training playground TicketOffice for the next lectures.
    Available
  • Mutex.withLock: a correct critical section

    Kotlin SELF
    Level 55, Lesson 1
    We break down why coroutines need Mutex and how to properly define a critical section via withLock: we protect not a “variable” but an invariant, keep the lock for the shortest possible time, avoid the anti-pattern of runBlocking inside helpers, and build a thread-safe expense ledger ( ExpenseLedger) with safe reads via snapshot().
    Available
  • AtomicInteger and AtomicReference: atomic operations and applicability limits

    Kotlin SELF
    Level 55, Lesson 2
    We break down the atomic types from java.util.concurrent.atomic on Kotlin/JVM: how AtomicInteger makes increment safe without Mutex, why the get() → set() combo does not “glue together” into atomicity, how CAS works via compareAndSet, and why AtomicReference<T> is almost always worth using with immutable state (via copy()). At the end: a tool-selection map and common mistakes.
    Available
  • Confinement and actor via Channel: single state owner

    Kotlin SELF
    Level 55, Lesson 3
    We break down the confinement approach in coroutines: how to eliminate races “by construction”, when mutable state belongs to a single owner and everyone else communicates with it via messages. In practice, we build an actor on top of Channel: a minimal counter without Mutex, a typed command protocol via sealed class, multiple senders, request/response via SendChannel, rules for correct shutdown ( Stop vs close()), and a set of typical mistakes.
    Available
  • Deadlock, livelock, and starvation: how they happen and how to avoid the trap

    Kotlin SELF
    Level 55, Lesson 4
    We break down three “anti-progress” states in concurrent Kotlin coroutine code: deadlock (mutual waiting), livelock (busy motion with no result), and starvation (tasks getting “starved” of CPU/time/locks). Using examples with Mutex, withLock, and tryLock(), we show how bugs are born from lock acquisition order, overly long critical sections, and “polite” retries—and then we fix it with rules: a single ordering by id, short withLock, backoff, and (when possible) a move to confinement/ actor design.
    Available
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym