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

Playing with @async is blocking #73

Closed
gstavrinos opened this issue Dec 1, 2018 · 7 comments
Closed

Playing with @async is blocking #73

gstavrinos opened this issue Dec 1, 2018 · 7 comments

Comments

@gstavrinos
Copy link

Hey Daniel,

I have a MWE for my problem:

using WAV
y, fs = wavread("sound.wav")
@async wavplay(y, fs)
while true println("async!") end

I would expect to see multiple "async!" messages, but I see only one. Any thoughs?

Thanks

@dancasimiro
Copy link
Owner

Which wavplay implemention are you using? Is it the pulse audio implementation or the native macOS implementation?

@gstavrinos
Copy link
Author

Oh, yeah, sorry. I am on Ubuntu 18.04, so pulse audio!

@gstavrinos
Copy link
Author

Any updates on this?

@dancasimiro
Copy link
Owner

I’m sorry, but I don’t have time to track this issue down. I am accepting pull requests though.

@gstavrinos
Copy link
Author

Sure, no problem. I'll see what I can do, but my schedule is tight too! Thank you!

@mgkuhn
Copy link
Contributor

mgkuhn commented Aug 1, 2020

@async just creates a task (for co-routines) and does not run it in another thread, so your example works sequentially (single-threaded), as expected.

For what you wanted, try to spawn a task into an available thread:

$ cat test.jl
using WAV
using Base.Threads
y, fs = wavread("example.wav")
Threads.@spawn wavplay(y, fs)
while true println("async!") end
$ JULIA_NUM_THREADS=2 julia test.jl

Note that Threads.@spawn is still an experimental feature as of Julia 1.4.

What I think you probably really wanted: if a backend provides asynchronous playback (i.e., tell the C function call to return immediately), we could expose this to the user e.g. as wavplay(y, fs; async=true).

The Windows backend apparently can do this: we could replace the flag SND_SYNC with SND_ASYNC, although I'm not sure if this alone is memory safe (as Julia might garbage-connect the waveform buffer before it is played asynchronously). I don't know yet about the other backends.

@dancasimiro
Copy link
Owner

closing due to lack of follow up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants