Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a cross-platform C signal library available(better open-sourced)?

I'm recently working on a project in which I need to port a portion of Linux C code to Windows. The code uses Linux signal mechanism(I mean the "sigaction", "sigprocmast", etc...) which is not well supported on Windows.

Is there a C/C++ library available that implements the cross-platform signal mechanism(better open-sourced)? Currently I just need the library to support Linux & Windows.

I think this question would also make sense to you because you might be given a similar task some day.

One of my colleagues told me that ACE is a powerful library that implements cross-platform signal mechanism perfectly, but he said it's a huge library and would really take some time to study it. My project doesn't give me too much time so I'm trying to look for a light-weight and easy-to-study signal library. (Hmm.. well, if the libraries you know about are all pretty big, please also tell me. :-)

I've done a lot of research on this subject with Google but I couldn't find what I want. Here is what I have done so far:

  1. Searched in Stackoverflow.com. People asked a lot of details about how to use signals in Linux but nobody seemed to ask about cross-platform signal implementation.

  2. Or, in Stackoverflow.com, people asked a mechamism called "signal-slot". I don't think that is what I need.

  3. Searched in entire google. I tried the key words "C signal "cross platform" OR cross-platform -game -python -gui -audio -digital -analysis -slot -image -processing -socket -time -directmedia" but couldn't find what I want.

Please help! Thanks!

like image 839
yaobin Avatar asked Feb 23 '11 14:02

yaobin


2 Answers

I've come over the problem some time ago. The big problem is that there is NO paradigm equivalent with signals on windows. The way it is done is just different.

I found that when I wanted to port some software from Linux to windows using pthread library. I was glad to find out that there a port of pthread ! Great ! But they explicitly state in their doc that have only implemented the pthread_kill(signal) API call with signal 0 (IIRC), with only gives you the state of the thread (eg it is running or not).

When you look at portable thread libs (like in boost) they use interruption points to handle the difference between the two models/paradigm.

To conclude, it depends on how signals are used in the application you're porting. You can surely port some behavior handled by signal on Linux to windows, but you certainly can not port the signal system 'as is'.

And I've found the hard way that it is not easy to do that when you use signal to interrupt sleeping system calls ^^

If there is a solution, I'm glad to hear from other answers ^^

my2c

like image 184
neuro Avatar answered Oct 27 '22 00:10

neuro


You should probably look into CYGWIN.

The problem with signals on Windows is that they just don't exist. Windows isn't POSIX and uses an almost entirely different methodology when it comes to application management. Its like asking where the spark plugs are on a hang-glider, there aren't any:)

like image 33
Unsigned Avatar answered Oct 26 '22 23:10

Unsigned