billthefarmer / mididriver

Android midi driver using Sonivox EAS library
176 stars 52 forks source link

Android studio files changed, code formatting, running while queue is not empty #10

Closed jhindin closed 9 years ago

jhindin commented 9 years ago

Android studio files changed, code formatting, running while queue is not empty

billthefarmer commented 9 years ago

I have merged this, but having looked at the changes I am not convinced that it works. If there are no midi events queued, then surely the driver loop will exit and shut down.

jhindin commented 9 years ago

In the case when midi events are left in the queue upon stop, the code contains race condition: the events left in the queue after the consumer thread stop, would be send when the driver restarts.

The event queue has to be drained or emptied on stop. The solution presented in the patch drains the queue; potentially, if application stops the midi driver but continues sending the events, the consumer thread would not stop, but such code is problematic anyway.

Regards,
  Joseph Hindin