开发者

Linux/vxworks signals

开发者 https://www.devze.com 2023-03-04 18:18 出处:网络
I came across the following in a vxworks manual and was wondering why this is the case. What types of things do signals do that make them undesirable?

I came across the following in a vxworks manual and was wondering why this is the case.

What types of things do signals do that make them undesirable?

In a开发者_JAVA技巧pplications, signals are most appropriate for error and exception handling, and not for a general-purpose inter-task communication.


The main issue with signals is that signal handlers are registered on a per process/memory space basis (in vxWorks, the kernel represents one memory space, and each RTP is a different memory space).

This means that regardless of the thread/task context, the same signal handler will get executed (for a given process). This can cause some problems with side-effects if your signal handler is not well behaved.

For example, if your signal uses a mutex for protect a shared resource, this could cause nasty problems, or at least, unexpected behavior

  Task A                       Task B               Signal Handler
  Take  Mutex
   ...
   Gets preempted 
                                does something
                                 ....
                                <SIGNAL ARRIVES>----->Take Mutex  (blocks)
   resumes
   ....
   Give Mutex
                                                ----->Resumes Handler

I'm not sure the example above really conveys what I'm trying to. Here are some other characteristics of signals:

  • Handler not executed until the task/process is scheduled. Just because you sent the signal, doesn't mean the handler will execute right away
  • No guarantee on which Task/Thread will execute the handler. Any thread/task in the process could run it (whichever thread/task executes first). VxWorks has ways around this.

Note that the above only applies to asynchronous signals sent via a kill call.

An exception will generate a synchronous signal which WILL get executed right away in the current context.

0

精彩评论

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