signals - what if multiple libraries set SIGIO handler !? ( alsa async interface ) [SOLVED]
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
signals - what if multiple libraries set SIGIO handler !? ( alsa async interface ) [SOLVED]
Hi Guys.. quick question...
Im new to the concept of signals, so this might sound stupid,
BUT....
I believe the alsa library uses SIGIO to drive the
asynchronous *give me more sound data* callback functions.
In the future, im also planning on incorporating
a library ( written by a 3rd party ) into my software
that accesses some hardware over a serial port, which i beleive can also use SIGIO to report that data is ready to be read.
I take it that theese two libraries are going to conflict !?
one will overwrite the others signal handler via sigaction !?
Or is linux doing somthing clever going on behind the scenes that
calls both signla handlers ?
I would guess this kind of problem arises frequently, but google turned up nothing... should i start re-thinking my design now!?
Linux does not do any magic: there can only be one signal handler per signal for a process. You cannot escape the limitation using threads, either: all threads have the same signal handlers in a process.
However, signals can be chained. It is not that hard to implement, either. Most programmers just do not bother to. Whether ALSA or your 3rd party library chains the signals, I have no idea.
If I were to guess, I'd say they will conflict. I don't believe either library chains their signals.
If you were to recompile one or both libraries for your application, you could of course use another signal, perhaps a realtime signal (SIGRTMIN+n), instead of SIGIO. All the kernel interfaces allow the process to specify a different signal, so it is just a question of whether the library supports it. For ALSA, it is defined when the library is compiled.
There are various ways to solve the signal conflict, if you wish to rely on the libraries being already installed on the system. The simplest, and usually the best one, is to separate the two parts -- ALSA access and the 3rd party library access -- into separate processes, and have the two parts communicate via pipes or sockets. The reason this is usually the best one, is that you'll find that the requirement for the pipe/socket communications creates an abstraction you can use to split your application into more easily managed chunks. Eventually, you might find that you could very easily replace the ALSA interface with something totally different. Usually the same applies to the hardware interface parts.
Think of the slave process(es) as interface processors, doing all device-specific magic, only working with abstract, device-independent data (formats) with other processes of your application. You'll usually have a third, master process, which controls and directs the actions of the other processes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.