https://github.com/shubhamv108/concurrency-multithreading
Sample examples of multi-threaded code in Java.
https://github.com/shubhamv108/concurrency-multithreading
concurrency consumer-producer context-switching count-down-latch cyclic-barrier multi-threading mutex mutex-synchronisation semaphore thread
Last synced: 3 months ago
JSON representation
Sample examples of multi-threaded code in Java.
- Host: GitHub
- URL: https://github.com/shubhamv108/concurrency-multithreading
- Owner: shubhamv108
- Created: 2020-09-30T11:59:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-21T17:15:01.000Z (5 months ago)
- Last Synced: 2025-01-29T22:44:46.257Z (5 months ago)
- Topics: concurrency, consumer-producer, context-switching, count-down-latch, cyclic-barrier, multi-threading, mutex, mutex-synchronisation, semaphore, thread
- Language: Java
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Thread
- Lightweight process responsible for executing a task#### Process vs Thread
- Process is isolated. | Threads share memory.
- Process switching uses interface in operating system | Thread switching does not require to call a operating system and cause an interrupt to the kernel.
- PCB, Stack, Address space | PCB, TCB, Stack, common Address space
- A thread is a path of execution within a process. A process can contain multiple threads.
- more time for context switching. | less time for context switching.#### PCB
- Process Id
- Process state
- Process priority
- Accounting Information
- Program Counter
- CPU Register
- PCB Pointers
- .....#### TCB
- Thread ID
- Thread State
- CPU Information
- Program Counter
- Register contents
- Thread Priority
- Pointer to process that created this thread
- Pointers to other threads that were created by this thread** https://www.geeksforgeeks.org/thread-control-block-in-operating-system/?ref=rp
#### Address Space
valid addresses in memory that are available for process.#### Process in Java
https://www.geeksforgeeks.org/java-lang-process-class-java/#### Links
- https://www.geeksforgeeks.org/thread-models-in-operating-system/?ref=rp
- https://www.geeksforgeeks.org/thread-in-operating-system/?ref=rp
- https://www.geeksforgeeks.org/mutex-lock-for-linux-thread-synchronization/?ref=rp
- https://www.geeksforgeeks.org/kernel-in-operating-system/?ref=rp
- https://www.geeksforgeeks.org/difference-between-user-level-thread-and-kernel-level-thread/?ref=rp
- https://www.geeksforgeeks.org/difference-between-process-and-kernel-thread/?ref=rp
- https://www.geeksforgeeks.org/difference-between-operating-system-and-kernel/?ref=rp#### Concurrency vs Parallelism (ToDo)
##### Parallel
- multiple things at same time
- genuine simultaneous execution
##### Concurrency
- multiple things together but not same time
- appearance of simultaneous execution (by interleaving of processes in time)#### False Sharing
- https://dzone.com/articles/what-false-sharing-is-and-how-jvm-prevents-it
- https://medium.com/@rukavitsya/what-is-false-sharing-and-how-jvm-prevents-it-82a4ed27da84## Critical Section
a piece of code that accesses a shared resource, usually a variable or data structure.## Race Condition
a software error that occurs when multiple threads access a shared resource## Intermediate Program
- Consists of 1 or * race conditions;
- the o/p of program is not deterministic & varies from run to run.## Mutual Exclusion
no two processes can exist in the critical section at any given point of time## InterProcess Communication
- coordinate and synchronize between processes
- ways
1. Pipes
2. Signals
3. Buffers: Message queues etc
4. Sockets## Shared memory
- Common memory region from PCB## AssemblerInstructions
#### ldsub
load/store unsigned instruction byte (locked version of atomic exchange)
#### xchg
atomic exchange