0

[NOOBS QUESTION] Good evening to everyone. First, sorry for my English, I'm trying to know better this language.

I've three files:

Main.cpp -> Contain the graphics interface, menu thread and audio thread. Lettore.cpp -> Contain the functions to reconize the type of the file and use the correct library for play the audio, also contain the function for stop, play,pause,skip a song. The two audio code library -> That decode the track and send it to ao for playing.

Now the question is: How I can implement this? My difficulty is in the main file. I write the "menu"("play/pause,skip,ecc....) thread code. Now the audio thread must be separated from the main(because can't block the program, the function for play is in a while), but must communicate with menu thread... How I can do this?

I'm using g++ with C++11 thread module. Thank you for your time

Ps: if this question isn't congruent with the rules i modify this question instantly!

Delayer
  • 409
  • 1
  • 5
  • 17

2 Answers2

1

If you are using pthread, use mutex variables or queues. There are lot of example available for pthread communication. pthread mutex variables to communicate among threads

inter thread communication

Community
  • 1
  • 1
lxkarthi
  • 336
  • 4
  • 14
1

Use a queue common to menu and audio thread. Menu thread fills the queue with commands and the audio thread occasionally checks it.

You can find one implementation of a lock-free thread safe queue in http://moodycamel.com/blog/2013/a-fast-lock-free-queue-for-c++

Blaz Bratanic
  • 2,279
  • 12
  • 17