ooooh, why didn't we think about that one?!

Lock-free atomic data structures.

Most of the locking/synchronisation fun we have is because we need to
insert things into lists.

Inserting tracks into the track list, inserting parts into the part
list, inserting events into the eventlist. In most situations, this is
the only critical action that.

Also, we might claim one advantage for us, if neccessary: Usually,
threads which *write* to data structures are not time critical. So we do
not need to care about two concurrent writes to be safe, we may just
mutex-lock here.
Only concurrent write and read must be safe and lock-free

Lock-free data structures exist! There's not only ringbuffers, but also
linked lists that can have atomic operations, I'll read more about this
soon.


But for our situation, such a list could be written trivially easy:
Qt offers us QAtomicPointers which, well, are atomical ;)

So our list nodes look like this:

struct list_node_t {
        data_t* pointer_to_data;
        QAtomicPointer<list_node_t> next;
        QAtomicInteger refcount;
};

Reading from this list works just like linked lists usually work.

Inserting will prepare the new node, and only at the end it will
(atomically) set the precedessor's "next"-pointer to itself.

If concurrent read access happens in the meantime, then it will either
see the new node and use it correctly, or it will see the old version of
the list. No data structure corruption :)


Deleting will also be just one atomic pointer change. The deleted list
node may *NOT* be free()d yet, since other threads might still hold that
one. But that can be solved, too.



That way, as opposed to what i said before, MIDI data does *not* need to
be prefetched. Instead, GUI and Audio thread just concurrently access
the same data structure. Since all operations on MIDI can be atomically,
this will be not a problem at all! (Except for recording. Need to read
more about the topic.)




I also talked to a developer of the ModPlug Tracker, which is a music
tracker software for windows. Trackers are a bit easier, because all
data is arranged in a fixed-size "grid". They aren't locking anything.
They're just writing and reading data concurrently; everything that
would lead to data corruption is done with atomic pointers or integers,
and the really tiny rest is actually done by putting audio in IDLE state.


I hope that lock-free, atomic data structures could greatly help us :)

What do you think? Tim, Robert?

Cheers,
flo

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
Lmuse-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lmuse-developer

Reply via email to