Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ways to wait for libmms asynchronously #564

Open
crocket opened this issue May 22, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@crocket
Copy link

commented May 22, 2019

C++ future

  • Make a future.
  • Make another thread. Pass the future to it.
  • Call libmms in the new thread.
  • If libmms is destined to time out in a few minutes and mpc clear is executed, assign null to the future in the main thread. Let the new thread fizzle out in a few minutes.
  • Otherwise, poll the value of the future on a regular basis. Or, wait for the future in another thread.

Queue

  • Make a thread-safe queue.
  • Make a new thread, and pass the queue to the new thread.
  • Call libmms in the new thread, and wait for it synchronously in the new thread.
  • If mpc clear is executed before libmms completes or times out, assign null to the queue in the main thread, and let the libmms thread fizzle out in a few minutes.
  • Make another thread. Pass the queue to the third thread.
  • Wait for libmms to send the result through the queue in the third thread.

Something else???

Since I don't exactly know how and why MPD waits for libmms, something else might be the solution.

@MaxKellermann

This comment has been minimized.

Copy link
Member

commented May 22, 2019

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.

@crocket

This comment has been minimized.

Copy link
Author

commented May 22, 2019

If mpc clear or mpc pause is executed before libmms returns a result or times out, you could create a new thread for background garbage collection, pass unused resources to the thread, and allocate new resources to the main thread.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.