The callbacks are cleared and blocking mode is set in one atomic
operation, so no callback gets called in between if the backend
is running in another thread.
Even so, if the stream is in callback mode (i.e. if any
callbacks are installed) then only the backend thread can use
this function reliably; it might otherwise already be running in
a callback which is about to call e.g. write when the stream
becomes blocking.