开发者

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

开发者 https://www.devze.com 2023-02-13 11:06 出处:网络
I\'m recently开发者_JS百科 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...) whi

I'm recently开发者_JS百科 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!


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


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:)


You can try porting your library using cygwin. There are several applications following the same way.


Just doing some research and found Writing POSIX-Standard Code on the Microsoft TechNet.

I looks like it gives some more (longer) reasoned details about what is similar and what is different, and what can, can't and could be done in one's code for porting Unix/Linux code.

It is part of a bigger set of info (see the hierarchy side bar)which I haven't had time to even browse...

Beyond CYGWIN, there is also MSYS and MinGW.

There also appears to be a bit of friction (or more often indifference) between the communities, with few folks spanning the divide.

0

精彩评论

暂无评论...
验证码 换一张
取 消