473,785 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what can be used in a signal handler

hg
Hi,

I posted an equivalent question earlier ... but am still not sure:

I currently (under Linux) have a program that uses Queue.put (raw_input(''))
in a signal handler and Queue.get() in the main/only thread.

It works but I want to know if it is legal / what type of synchro API I have
the right to use in a signal handler.

Regards,

hg

Jan 18 '07 #1
2 1488

In article <3z************ *******@newsfe2 1.lga>,
hg <hg@nospam.orgw rites:
|>
|I posted an equivalent question earlier ... but am still not sure:
|>
|I currently (under Linux) have a program that uses Queue.put (raw_input(''))
|in a signal handler and Queue.get() in the main/only thread.
|>
|It works but I want to know if it is legal / what type of synchro API I have
|the right to use in a signal handler.

Strictly, no and none.

C and POSIX's specifications of signal handling is a complete mess.
ALL handling of ALL real signals is undefined behaviour, though few
programmers realise that and POSIX depends on it. As that would make
all Unices (and Microsoft systems) unusable, you can reasonably assume
that there is some signal handling that will work.

But what? Which is where you came in.

The situation is that most things that seem to work do actually work,
in some environments and under some circumstances. You can never be
sure when they will stop working, however, and all bets are off when
you port signal handling code to a new system. And, really but REALLY,
do not mix it with very high levels of optimisation or rely on it
being in any way thread safe.

I can't tell you whether the code of Queue is intended to work if an
active Queue.get is interrupted by a signal which then does a Queue.put,
but that is the sort of circumstance where things get very hairy. Even
if Python has code to enable that case, it won't be 100% reliable on all
systems.

Sorry. But that is the situation :-(
Regards,
Nick Maclaren.
Jan 18 '07 #2
hg
Nick Maclaren wrote:
>
In article <3z************ *******@newsfe2 1.lga>,
hg <hg@nospam.orgw rites:
|>
|I posted an equivalent question earlier ... but am still not sure:
|>
|I currently (under Linux) have a program that uses Queue.put
|(raw_input('') ) in a signal handler and Queue.get() in the main/only
|thread.
|>
|It works but I want to know if it is legal / what type of synchro API I
|have the right to use in a signal handler.

Strictly, no and none.

C and POSIX's specifications of signal handling is a complete mess.
ALL handling of ALL real signals is undefined behaviour, though few
programmers realise that and POSIX depends on it. As that would make
all Unices (and Microsoft systems) unusable, you can reasonably assume
that there is some signal handling that will work.

But what? Which is where you came in.

The situation is that most things that seem to work do actually work,
in some environments and under some circumstances. You can never be
sure when they will stop working, however, and all bets are off when
you port signal handling code to a new system. And, really but REALLY,
do not mix it with very high levels of optimisation or rely on it
being in any way thread safe.

I can't tell you whether the code of Queue is intended to work if an
active Queue.get is interrupted by a signal which then does a Queue.put,
but that is the sort of circumstance where things get very hairy. Even
if Python has code to enable that case, it won't be 100% reliable on all
systems.

Sorry. But that is the situation :-(
Regards,
Nick Maclaren.
Fair, I'll find a way around then.

Regards,

hg
Jan 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6815
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
2
2212
by: lpw | last post by:
I have dilligently reviewed FAQ-lite Section 3.2, "How do I pass a pointer-to-member-function to a signal handler, X event callback, system call that starts a thread/task, etc." The only suggestion on how to deliver a signal to an object is to do it via a global variable and a wrapper function, a technique that is generally a Bad Idea (due to the usage of a global variable). I understand that this ng is dedicated to the discussion of...
3
3526
by: Martin McCormick | last post by:
A C program contains several signal statements to remove a lock file if the program gets killed: /*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/ signal(SIGINT,crash); signal(SIGBUS,crash); signal(SIGSEGV,crash); This part works. Those signals cause the "crash.c" module to run and get rid of the lock. Is there a standard way to also print
3
2198
by: subnet | last post by:
I'm trying to write a very simple program that uses a signal-based synchronization between two processes. Here's it: ----------------------------------------------- /* The world's simplest syncronization example */ #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> void handler(int sig);
11
2975
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
5
2613
by: Sontu | last post by:
Hi all, Consider the following code: #include<signal.h> #include<stdio.h> #include<sys/mman.h> void handler(int sig) {
4
2102
by: manochavishal | last post by:
Why would a signal handler cannot in general call standard library functions. I have read whats is said in Standard but needs an explaination on that as i couldn't uunderstand it. Thanx in advance
10
4036
by: subramanian | last post by:
Consider the following code: segment violation is deliberately generated to catch the SIGSEGV signal. The handler for this signal, namely SIGSEGV_handler, is called. However after the handler is finished, control does not return to the printf statement in main() which is present after the strcpy statement. Instead Segmentation violation error message is printed in Redhat Linux and the program is aborted. In VC++, the SIGSEGV_handler is...
1
2445
by: stalex | last post by:
Hi all, I wrote the following code since I want to try using a decorator to install signal handler: ## The test.py script ################# import os import time import signal
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.