[alsa-devel] cloning snd_seq_t (or creating one from client id)

Tobias Schlemmer Tobias.Schlemmer at tu-dresden.de
Mon Mar 31 16:40:20 CEST 2014


Am 31.03.2014 14:29, schrieb Clemens Ladisch:
> Tobias Schlemmer wrote:
>> I'm surprised that the upcoming version of RtMidi uses one ALSA client
>> per MIDI port.
>>
>> I found out that sequencer handles (snd_seq_t) are not thread safe.
> A sequencer client use a common buffer for the events of all ports.
Yes. Thus, I suggested to split the set of ports of a client into
disjoint subsets. Then each sequencer would handle only one of these
subsets, which should reduce the interference with other ports' code.
>> Could you provide some way to implement multithreaded ALSA clients?
> Multiple threads would have to synchronize the buffer accesses in some
> way.
That is not true. Programmers tend to program lock free, as locking
creates always a bottleneck. Other problems can occur if have different
load and different priority to the program. The current aproach that is
taken by kmid and RtMidi is to use different sequencers. The ALSA docu
suggests to use different sequencers in the latter way. Unfortunately
this does not comply with the idea of clients and ports as they are
presented to end users. So I suggested to hide this implementation
detail from the end user and present him all ports from all sequencers
of a program instance under one common client id. The port ids used in
the sequencers should be the same as the ones that are presented to the
end user in order to prevent unexpected behaviour.

How exactly merging and distributing of events from/to multiple
ports is handled (even when some thread does not react) is a policy that
cannot be imposed by the ALSA library.

The current policy is forcing the client to serialise events of
different connections that don't interfere. The ALSA imposes a policy
that is obviously is not necessary from a technical point of view as
every program instance can use different sequencer clients already with
the current implementation at the cost of worsening the usability. My
suggestion is to losen this restriction.

Regards,

Tobias

P.S.: We are talking about the library API right?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x73A2F90C.asc
Type: application/pgp-keys
Size: 4302 bytes
Desc: not available
URL: <http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20140331/669262fc/attachment.bin>


More information about the Alsa-devel mailing list