Results for “Tasks & synchronization”
Small, practical examples. Search by task or narrow things down below.
Check whether a future is ready without blocking
C++: A zero-duration wait reports timeout until the producer sets a value.
C++✓ Tested
Convert a duration to another unit explicitly
C++: duration_cast converts units and truncates fractional integer units.
C++✓ Tested
Deliver a result through a promise and future
C++: A promise sets a shared state and its future retrieves the value.
C++✓ Tested
Increment a shared counter safely
C++: Atomic increments prevent lost updates when two threads change the same counter.
C++✓ Tested
Observe an exception from an asynchronous task
C++: Calling get rethrows an exception captured by the future.
C++✓ Tested
Pass an argument into a worker thread
C++: Thread arguments are copied by default; std::ref explicitly passes a reference.
C++✓ Tested
Protect a shared container with a mutex
C++: A scoped lock_guard releases the mutex when its scope ends.
C++✓ Tested
Retrieve the result of an asynchronous task
C++: The explicit async launch policy requests asynchronous execution rather than deferred evaluation.
C++✓ Tested
Run a task on a thread and join it
C++: Join before reading a result written by the worker thread.
C++✓ Tested
Wait for shared state with a condition variable
C++: Use a predicate so spurious wakeups cannot allow the worker to continue before the state is ready.
C++✓ Tested
Await multiple tasks while preserving result order
C#: Task.WhenAll returns results in the same order as the supplied tasks.
C#✓ Tested
Reuse document-title synchronization
Reuse document-title synchronization with a small React component and explicit browser behavior.
React✓ Tested