From: Daniel Yek <dyek@real.com>
To: "Rémi Denis-Courmont" <rem@videolan.org>
Cc: alsa-devel@alsa-project.org
Subject: Re: How to close ALSA device nodes?
Date: Thu, 22 Oct 2009 15:55:33 -0700 [thread overview]
Message-ID: <4AE0E2E5.2040604@real.com> (raw)
In-Reply-To: <200910182038.34252.rem@videolan.org>
Could it be that the answer is to use the surrogate parent model?
Book: Pthreads Programming:
http://books.google.com/books?id=2kZDx8H6H18C&pg=PA190&lpg=PA190&dq=Multithreading+surrogate+parent+model&source=bl&ots=nmEnmuPQme&sig=-MvAQEZUJngOdMLJ-HGhAqCv1AU&hl=en&ei=_eDgSqWYLYacsgOB_eHODA&sa=X&oi=book_result&ct=result&resnum=1&ved=0CAwQ6AEwAA#v=onepage&q=&f=false
<http://books.google.com/books?id=2kZDx8H6H18C&pg=PA190&lpg=PA190&dq=Multithreading+surrogate+parent+model&source=bl&ots=nmEnmuPQme&sig=-MvAQEZUJngOdMLJ-HGhAqCv1AU&hl=en&ei=_eDgSqWYLYacsgOB_eHODA&sa=X&oi=book_result&ct=result&resnum=1&ved=0CAwQ6AEwAA#v=onepage&q=&f=false>
That is, the multi-threaded app. creates a dummy child process during
its initialization process and use the child solely as a surrogate
parent to fork on behalf of the app. That way, the multi-threaded app.
doesn't have to fork and possibly leaking "states" in the child
(especially, if it is not followed by an exec(), I think.)
I'm interested in hearing from the more experienced devs. regarding this
technique too.
Regards,
--
Daniel Yek.
Rémi Denis-Courmont wrote:
> Le dimanche 18 octobre 2009 20:13:15 Robert Hancock, vous avez écrit :
>>> From the earlier thread, I reckon that ALSA developers consider that
>>> this
>>> is an upper-layer issue. Maybe so, but then how is the upper-layer
>>> supposed to find which file descriptors ALSA-lib has opened - if any?
>>> Conversely, if ALSA- lib won't tell while file descriptors it is using,
>>> what could possibly be the use case for not closing those on exec?
>> I agree that it's a difficult problem for an app that wants to fork
>> and exec another process.. I'd think really should be some way for an
>> app to control the CLOEXEC flag for the file descriptors that alsa-lib
>> has open..
>
> Right. The kernel recently introduced the O_CLOEXEC open flag, to support
> thread-safe close-on-exec. The only way to leverage this is for
> ALSA-lib to
> set close-on-exec itself when it opens a file (whether by default or
> when the
> application requests it).
>
> That said, I still fail to see any potential use case to not set the
> flag.
> Since ALSA-lib won't let the application know about the file handles, any
> application cannot a use them across exec() in the first place. For the
> reference, glibc is now setting close-on-exec in similar cases, e.g.
> syslog().
>
>> I guess the alternative would be to shutdown all open PCMs, etc. in
>> ALSA in the child process after forking and before the exec, so that
>> they don't end up still open for the new process..
>
> I suspect such an approach would be painful both for ALSA and for the
> applications. From ALSA, this would need safety with regards to fork in
> another thread. That probably requires pthread_atfork() *glurp* if
> ALSA is to
> keep its SMP & thread-safety promise *ouch*. From the application, this
> require calling an ALSA function between fork and exec. That would forbid
> using system(), popen() or -faster- posix_spawn*(). That also means
> linking to
> ALSA in every place that executes. Considering that VLC is heavily plugin-
> based, this would be so impractical that I'd even rather scan through
> /proc/self/fd...
>
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
next prev parent reply other threads:[~2009-10-22 22:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-18 17:38 How to close ALSA device nodes? Rémi Denis-Courmont
2009-10-22 22:55 ` Daniel Yek [this message]
2009-10-23 9:49 ` Rémi Denis-Courmont
2009-10-23 16:44 ` Surrogate Parent Model / " Daniel Yek
2009-10-23 18:51 ` How to close ALSA device nodes? / ALSA's fds Daniel Yek
2009-10-24 14:37 ` Rémi Denis-Courmont
-- strict thread matches above, loose matches on Subject: below --
2009-10-18 16:06 How to close ALSA device nodes? Rémi Denis-Courmont
2009-10-18 17:13 ` Robert Hancock
2009-10-18 16:02 Rémi Denis-Courmont
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AE0E2E5.2040604@real.com \
--to=dyek@real.com \
--cc=alsa-devel@alsa-project.org \
--cc=rem@videolan.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox