Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 2.27 KB

File metadata and controls

50 lines (33 loc) · 2.27 KB
coverY
0

Introduction

Why MultiThreading?

  • Better CPU Utilization
  • Better IO Utilization
  • Higher application responses

Issues with Multi-Threading

Shared Mutable State issues:

  • Race Conditions
  • Invisible Writes
  • Congestion
  • DeadLock
  • Nested Monitor Lockout
  • Starvation
  • Slipped Condition
  • Missed Signals

No Shared Mutable state concurrency:

  • Separate State Concurrency
  • Functional Paralleism
  • Parallel Pipelines

Multi-Threading Costs:

  • More Complex Design - Code executed by multiple threads accessing shared data need special attention. Thread interaction is far from always simple. Errors arising from incorrect thread synchronization can be very hard to detect, reproduce and fix.
  • Context Switching Overhead - When a CPU switches from executing one thread to executing another, the CPU needs to save the local data, program pointer, etc. of the current thread, and load the local data, program pointer, etc. of the next thread to execute. This switch is called a "context switch". The CPU switches from executing in the context of one thread to executing in the context of another.
  • Increased resource consumption - Threads needs some memory to maintain its local stack it consumes more resources inside OS.

Appendix:

Type Use Case
Volatile Flags

AtomicInteger
AtomicLong

Counters
AtomicReference
  1. Caches (Building new cache in the background and replacing atomically)
  2. Used By some internal classes
  3. Non Blocking Algorithms