thread-safe
Code that behaves correctly when several threads use it at the same time.
In more detail
Shared objects, such as singletons in a web server, must be thread-safe because many requests use them at once. The easiest route is to hold no mutable state; otherwise use locks or concurrent collections.
Related terms
- singleton — A service lifetime, or design, in which one instance is created and shared for the whole life of the process.
- thread — A path of execution inside a process that the operating system schedules on a processor; one process can have many.
- Atomics — A JavaScript object of functions that read and change shared memory in steps that cannot be interrupted by another thread.
- mutex — A lock that lets only one piece of code at a time run a critical section or do a particular piece of work.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
Taught in
- The Dependency Injection Container: Scopes and Lifetimes — Modern .NET Core, C# & Enterprise Microservices
- Worker Threads: worker_threads & SharedArrayBuffer — Node.js Internals & Backend Services
- Routing & Middleware: Path Parsing & Async Context — Node.js Internals & Backend Services