
25 Nov
2014
25 Nov
'14
2:04 p.m.
Takashi Sakamoto wrote:
On Nov 24 2014 22:54, Clemens Ladisch wrote:
In theory, it would be possible to use atomic_t to synchronize multiple streams, but this requires that
- two CPUs that start a stream at the same time do not both think they are the first, ... and
- when one CPU is still starting a stream, code on all other CPUs must be able to work correctly, without synchronization. [...]
If I rewrite your pseudo code, like this:
void start_some_substream(...) { if (atomic_inc_and_test(substreams)) { mutex_lock(); // lots of stuff to start DMA ...
if (wait_for_first_packet() == ETIMEDOUT) { stop_dma(); release_streams(); mutex_unlock(); return ETIMEDOUT; }
mutex_unlock(); } ...
}
This is an even better example of why atomic_t is incorrect: when the startup fails, the second call to start_some_substream() at the same time, which just sees that substreams>0, cannot notice the error, and thinks its own substream has been started successfully.
Regards, Clemens