Skip to content

Concurrency async

Concept C# Java Python JavaScript Go C++ Rust Kotlin Swift
Threads System.Threading.Thread java.lang.Thread threading - Goroutines std::thread std::thread - -
Thread Pools System.Threading.ThreadPool java.util.concurrent.ExecutorService - - - - - - -
Futures System.Threading.Tasks.Task java.util.concurrent.Future concurrent.futures Promise - std::future std::future - -
Async/Await System.Threading.Tasks.Task - asyncio Promise, async/await - - async-std, tokio kotlinx.coroutines async/await
Event Loop - - asyncio Event Loop - - - - -
Coroutines - - - - - - - kotlinx.coroutines -
Channels System.Threading.Channels - - - chan - std::sync::mpsc - -
Mutex/Semaphore System.Threading.Mutex, System.Threading.Semaphore java.util.concurrent.locks.ReentrantLock, java.util.concurrent.Semaphore threading.Lock, threading.Semaphore - - std::mutex, std::semaphore std::sync::Mutex, std::sync::Semaphore - -
Task Management System.Threading.Tasks.Task java.util.concurrent.CompletableFuture - - - std::async - - -

Threads

A thread is the smallest unit of a process that can be scheduled and executed independently.

Thread Pools

A thread pool is a collection of pre-instantiated reusable threads that can be used to execute tasks, improving performance and resource management.

Futures

A future represents the result of an asynchronous computation, allowing you to retrieve the result once the computation is complete.

Async/Await

Async/await is a programming pattern that allows you to write asynchronous code in a synchronous style, making it easier to read and maintain.

Event Loop

An event loop is a programming construct that waits for and dispatches events or messages in a program, often used in asynchronous programming.

Coroutines

Coroutines are lightweight, cooperative threads that allow you to write asynchronous code without blocking the main thread.

Channels

Channels are a means of communication between concurrent tasks, allowing them to send and receive messages.

Mutex/Semaphore

A mutex (mutual exclusion) is a synchronization primitive that ensures only one thread can access a resource at a time. A semaphore is a signaling mechanism that controls access to a shared resource by multiple threads.

Task Management

Task management involves creating, scheduling, and managing the execution of tasks, often using futures or promises to handle asynchronous operations.

Additional Information:

  • Java: Java also supports ForkJoinPool for parallel processing.
  • Python: Python's multiprocessing module allows for true parallelism by utilizing multiple CPU cores.
  • JavaScript: JavaScript achieves parallelism using Web Workers and libraries like Parallel.js.
  • Go: Go's GOMAXPROCS setting allows configuring the number of threads for parallel execution.
  • C++: C++ provides std::async for asynchronous task management and parallel algorithms in the STL.
  • Rust: Rust's concurrency model leverages its ownership system and type checking to prevent data races at compile time.
  • Kotlin: Kotlin's coroutines are a powerful tool for asynchronous programming, offering lightweight concurrency.
  • Swift: Swift's concurrency model includes Grand Central Dispatch (GCD) and async/await for structured concurrency.
  • C#: C# supports parallel programming through the Task Parallel Library (TPL) and Parallel LINQ (PLINQ).