Simple threading question

Hi all! I’m trying to use Juce to create a GUI for the demo app of a library I’ve been writing. Although I’ve been programming for a bit, it has been in the games industry and I’ve never had to do any real threading or modern style applications…

Here’s the question. I’ve got my library running in its own Thread class, and my UI sitting there, and I’m wondering how I use Juce to communicate back and forth with the two. All I need is some simple messages and some strings back and forth. I’ve noticed the Message class but is that alright to use between threads and can I use it for strings?

Thanks.
:slight_smile:

u can try out ChangeBroadcaster and ChangLlistener classes for sending and receiving messages.[/b]

Hmmm 28 views and no suggestions. Maybe I should elaborate?

Once a (long) while ago I started doing something similar. The thread class had a list of messages and a volatile bool for locking. You’d then call thread->sendMessage(string s) which would lock and add the message to the end of the list to be parsed by the thread later. I imagine I’d just do the same for the other way round too.

For now I can do that again but the messaging all seems kinda close to what Juce has already. I’m just wondering if there’s a ‘Juce way’ of doing that?

EDIT: Thanks Godwin, noticed your post slightly too late. So the MessageListener, ChangeListener, ActionListener classes are fine between threads? Thanks. :slight_smile:

(apologies if this is all kinda noobish, in the last 10 years I somehow haven’t had to do anything with threaded programming… :oops: )

it depends on wat u r passing in the message… if u pass one object and eventually delete somewhere in the code there might be possibilities of dangling pointers. So be sure wat u r passing and how u r handling sent message. there are both synchronous and asynchronous messages are available.

Awesome cheers. Yeah, I’ve got most of the stuff talking nicely how it should now. I kinda know a little about the main rules of threading, I just had an small embarrassing piece of the puzzle missing regarding Juce… :lol:

Thumb rule make ur application thread safe…