J
jonathan
Hello all,
Just wondering if someone can help me with something I haven't done
in C++ before. I'd like to add a simple event loop to a music player
I've written. I'd like to know if I can do this in portable C++, or
will I need to insert some assembly language?
For context, the basic idea is that I have playback in one thread,
and UI in another. Currently I'm using the Qt libraries to handle
this. I don't mind this so much, but if I can remove the dependency
I'd like to.
I only need to be able to post messages to the playback thread like
"play", "stop", "pause", "new song", etc. Nothing extremely time
critical. I just don't want the (unlikely) event of losing messages.
My first thought was to create a "message" and add it to an event
queue 'as quick as possible'. Say,
last_queued_message->next = &my_newly_created_message;
I recognize that if I have two threads doing this at the same time
they could theoretically both write to "next" and one of them will be
lost. Can I get around this in C++? Do I need to use cmpxchg (I'm on
x86)?
Any ideas are much appreciated
--Jonathan
Just wondering if someone can help me with something I haven't done
in C++ before. I'd like to add a simple event loop to a music player
I've written. I'd like to know if I can do this in portable C++, or
will I need to insert some assembly language?
For context, the basic idea is that I have playback in one thread,
and UI in another. Currently I'm using the Qt libraries to handle
this. I don't mind this so much, but if I can remove the dependency
I'd like to.
I only need to be able to post messages to the playback thread like
"play", "stop", "pause", "new song", etc. Nothing extremely time
critical. I just don't want the (unlikely) event of losing messages.
My first thought was to create a "message" and add it to an event
queue 'as quick as possible'. Say,
last_queued_message->next = &my_newly_created_message;
I recognize that if I have two threads doing this at the same time
they could theoretically both write to "next" and one of them will be
lost. Can I get around this in C++? Do I need to use cmpxchg (I'm on
x86)?
Any ideas are much appreciated
--Jonathan