Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Ways to wait for libmms asynchronously #564
Since I don't exactly know how and why MPD waits for libmms, something else might be the solution.
libmms is already called in a dedicated thread, and MPD waits for completion asynchronously; what you listed is just different semantics of doing that. There's one thing MPD needs to wait synchronously for: cancellation. Because that libmms threads has references to objects which are going to be stale after cancellation, and if I pull the carpet away under that thread's feet, it will crash later.
The thread waits for result. After libmms times out, the garbage collection thread will destroy unused resources.
I think there won't be memory leak because TCP SYN request times out in minutes. Or, you could pass timeout to ffmpeg. You might want to set timeout to a reasonable value because it can take minutes to kill mpd during reboot or shutdown. I suggest 20~30 seconds unless the mms server is on mars.
You could also create a dedicated garbage collection thread. You can pass unused resources to the queue in the thread. The dedicated garbage collection thread would dispose of resources sequentially. The dedicated garbage collection thread could even pass garbages to the queues in several other subordinate garbage collection threads if you want concurrent garbage collection.