gordonklaus / portaudio

Go bindings for the PortAudio audio I/O library
MIT License
704 stars 95 forks source link

Changed initialized counter to atomic and moved initialize to a separate file #25

Closed JulianKnodt closed 6 years ago

JulianKnodt commented 6 years ago

Moved initialization related functions to a separate file and encapsulated a way to check to see if port audio was initialized

Motivation for this is because the variable was intertwined in multiple functions, and it was not safe for concurrent usage.

Moving it to a separate file separates it so it's easier for future development.

gordonklaus commented 6 years ago

Would you mind describing the situation in which you are calling Initialize and Terminate concurrently? In all my programs (which are admittedly simple) they are only called from the main goroutine.

JulianKnodt commented 6 years ago

I wanted to try to develop a library on top of this, and when creating multiple structs which all utilize Initialize and Terminate, it makes more sense to have it be thread safe.

I'm not sure if this fits your use case or is even necessary, but that's just from my perspective.

gordonklaus commented 6 years ago

I think the need for synchronization may be unique to your use case. I would suggest using a mutex in your own code.

ebiiim commented 5 years ago

I am trying to develop an desktop app using this library. When I tested the app with -race option, I got race detected during execution of test at initialized-- (l.143).

(when testing this code) https://github.com/ebiiim/eq/blob/f6c1ccde30adf78eacbd5cc4d4bd3e76851162ee/streamio/portaudio/recorder.go#L96

(data race is detected here) https://github.com/gordonklaus/portaudio/blob/00e7307ccd93051979a933c6fd5ead641eba5686/portaudio.go#L143

I understand this is not a practical issue, but IMHO -race compatibility makes us happy.

Can you please reconsider this pull request?