Multiple threads




I am a begginer with Juce and currently writting my first app. I am trying to use threads but I am finding some troubles and I think the demo and tutorial way is not the one I am after considering my needs (simple needs by the way).

I just want to have 2 threads for both receiving and transmitting data thru USB port. I have my class with USB stuff, so from this class i need to launch 2 different threads with access to some parameters to send and receive data.

But in the thread tutorial, it just inherits the thread stuff from the user class, such as ---- class myclass : public thread. So I would just would dispose of "only" one run (thread) function. and I need 2.

On the other hand in the demo example (creating and moving balls), the thread inherits the ball stuff, such as --- class mythread: public thread, public ballsclass. So for every thread, it created a class ball.

In my case, i need to launch 2 threads from the same class, having access to parameters from threads I dont find the way to do it. (maybe it will happen the same if I would like 2 different timers).

I have also tried to send parameters to threads by typecasting as I have usually done with other platforms.

thread_rx::thread_rx(void* arg) : Thread("RX Thread")

    cRX *pRX = (cRX*)arg; ....


but since I have to typecast in the constructor, I cant access to the class parameters in the run function. And the program doesnt compile if I create the pointer in the thread class, and the try to typecast...some kind of:

private: cRX *pRX;

thread_rx::thread_rx(void* arg) : Thread("RX Thread")

    cRX *pRX2 = (cRX*)arg;

   pRX2 = cRX; => doesnt work, since I would have to use "new" for creating the entire class again....and seems not proper typecasting style.


**So, any idea out there??should be easy. Just one to create a class with 2 threads frown

Thanks in advance.!




A main class that contains two classes (a receiver and an emitter) that inherit both from Thread?