Closed ikv closed 10 years ago
Thanks for the report! We should track which process creates each shared resource and only free them in the creating (parent) process.
On 01/15, Thomas Tuegel wrote:
Thanks for the report! We should track which process creates each shared resource and only free them in the creating (parent) process. That kind of approach to issue is never crossed my mind, interesting. Usually resources are managed by limiting scope of liveness. Something, like
withMixer :: String -> (Mixer -> IO ()) -> IO ()
, whereMixer
is closed as soon as action is finished. See, for exampleForeign.Marshal.Pool.withPool
,System.IO.withFile
, etc. Could you please elaborate on your decision to check pid instead?
On second thought: ignore me, those things are orthogonal.
I've implemented your suggestion as withMixer
, which explicitly manages the scope of the Mixer object and checks that the mixer is only freed by the parent process. I've uploaded version 0.2.0 to Hackage, please let me know if you have more problems!
Awesome, thank you.
Altho it would be nice, if documentation would specify that it would be Sound.ALSA.Exception.T
thrown on error.
Also, it's appears, that on failure snd_mixer_attach
does unconditionally spits this error message:
ALSA lib control.c:953:(snd_ctl_open_noupdate) Invalid CTL
.
Is there an easy way to shut it up?
If process is forked after newForeignPtr, but before finalizer is run, then one of the finalizers will fail due to shared resource (shm) already being freed. In some cases child segfaults too, although I did not found a reliable way to reproduce.
How to reproduce:
and the output I'm getting:
Why it's relevant: Because of XMonad. XMonad does all it's forks via forkProcess (see xfork soruce @ XMonad.Core). And if you want to query volume levels from the xmonad then alsa-mixer is the only sane option you got (parsing textual output of amixer is not)