Hardware interview practice
Control a background process lifecycle
Start a polling task in the background and later stop exactly that task through a stored process handle.
Reviewed example
Work through one case
Input
call start(), start(), stop(), stop()Expected output
one worker starts; second start is ignored; first stop kills that owned worker; final stop is a safe no-opPublishing the stored process handle before start returns removes the initialization race and targets only the intended background task.
What to cover
Requirements
- Starting the worker must not leave the caller racing an uninitialized handle.
- Ignore a second start while the worker is already active.
- Stopping must be safe when no worker is active.
