signals

C++11 observer pattern (signals, slots, events, change broadcaster/listener, or whatever you want to call it)

泪湿孤枕 提交于 2019-12-03 01:02:53
问题 With the changes made in C++11 (such as the inclusion of std::bind ), is there a recommended way to implement a simple single-threaded observer pattern without dependence on anything external to the core language or standard library (like boost::signal )? EDIT If someone could post some code showing how dependence on boost::signal could be reduced using new language features, that would still be very useful. 回答1: I think that bind makes it easier to create slots (cfr. the 'preferred' syntax

What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)?

孤街浪徒 提交于 2019-12-03 01:00:29
问题 What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)? Currently (I have done nothing special to handle unix signals), my PyQt application ignores SIGINT (Ctrl+C). I want it to behave nicely and quit when it is killed. How should I do that? 回答1: 17.4. signal — Set handlers for asynchronous events Although Python signal handlers are called asynchronously as far as the Python user is concerned, they can only occur between the “atomic” instructions of the

How are asynchronous signal handlers executed on Linux?

隐身守侯 提交于 2019-12-03 00:47:06
问题 I would like to know exactly how the execution of asynchronous signal handlers works on Linux. First, I am unclear as to which thread executes the signal handler. Second, I would like to know the steps that are followed to make the thread execute the signal handler. On the first matter, I have read two different, seemingly conflicting, explanations: The Linux Kernel, by Andries Brouwer, §5.2 "Receiving signals" states: When a signal arrives, the process is interrupted, the current registers

I have an error in main.m “Thread 1: signal SIGABRT” How can I fix this?

时光怂恿深爱的人放手 提交于 2019-12-03 00:43:33
My code in the main.m file is as follows. I haven't changed it at all from when I started programming this app. #import <UIKit/UIKit.h> #import "rickAppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([rickAppDelegate class])); } } I am getting the SIGABRT error on the 'return UIApplicationMain' line. My program is an app which displays a red button and when you press it, it plays a video. This error appeared after I implemented iAds using this tutorial: http://www.ioslearner.com/implement-iads-tutorial-iphone-ipad

How to determine if code is running in signal-handler context?

我只是一个虾纸丫 提交于 2019-12-02 23:43:25
I just found out that someone is calling - from a signal handler - a definitely not async-signal-safe function that I wrote. So, now I'm curious: how to circumvent this situation from happening again? I'd like to be able to easily determine if my code is running in signal handler context (language is C, but wouldn't the solution apply to any language?): int myfunc( void ) { if( in_signal_handler_context() ) { return(-1) } // rest of function goes here return( 0 ); } This is under Linux. Hope this isn't an easy answer, or else I'll feel like an idiot. Apparently, newer Linux/x86 (probably since

FATAL SIGNAL 11 (Sigsegv) at 0x00000000 (code=1)?

南笙酒味 提交于 2019-12-02 23:02:09
Why does this problem occur? public static String path; private VideoView mVideoView; mVideoView = (VideoView) findViewById(R.id.surface_view); mVideoView.setVideoPath(path); mVideoView.setMediaController(new MediaController(this)); mVideoView.requestFocus(); //... private int mLayout = VideoView.VIDEO_LAYOUT_ZOOM; @Override public void onConfigurationChanged(Configuration newConfig) { if (mVideoView != null) mVideoView.setVideoLayout(mLayout, 0); super.onConfigurationChanged(newConfig); } The error message you are seeing is caused by dereferencing a null pointer in native code. From what you

How to close a file?

℡╲_俬逩灬. 提交于 2019-12-02 20:45:20
I felt at peace with Posix after many years of experience. Then I read this message from Linus Torvalds, circa 2002: int ret; do { ret = close(fd); } while(ret == -1 && errno != EBADF); NO. The above is (a) not portable (b) not current practice The "not portable" part comes from the fact that (as somebody pointed out), a threaded environment in which the kernel does close the FD on errors, the FD may have been validly re-used (by the kernel) for some other thread, and closing the FD a second time is a BUG. Not only is looping until EBADF unportable, but any loop is, due to a race condition

Golang catch signals

拟墨画扇 提交于 2019-12-02 19:20:42
I want to implement a "process wrapper" in Go. Basically what it will do, is launch a process (lets say a node server) and monitor it (catch signals like SIGKILL, SIGTERM ...) I think the way to do is to launch the node server in a go routine using syscall.Exec : func launchCmd(path string, args []string) { err := syscall.Exec(path, args, os.Environ()) if err != nil { panic(err) } } Then I'd like to catch every possible signals generated by the command executed by syscall . I'm pretty new to Go, any help would be appreciated. Luke There are three ways of executing a program in Go: syscall

Signal handling and sigemptyset()

泄露秘密 提交于 2019-12-02 19:12:26
Could anyone please explain in a really easy way to understand what sigemptyset() does? Why is it useful? I've read a bunch of definitions but i just don't understand. From what i gather it tracks the signals that are being used for blocking purposes? I'm not really sure i understand why that would be useful. Is it so we do not get that specific signal recursively? Basic example where sigemptyset() is used: #include <signal.h> #include <stdio.h> #include <unistd.h> int main(){ struct sigaction act; sigemptyset(&act.sa_mask); act.sa_handler=function_name; act.sa_flags=0; sigaction(SIGINT, &act,

pthreads : pthread_cond_signal() from within critical section

强颜欢笑 提交于 2019-12-02 18:47:33
I have the following piece of code in thread A, which blocks using pthread_cond_wait() pthread_mutex_lock(&my_lock); if ( false == testCondition ) pthread_cond_wait(&my_wait,&my_lock); pthread_mutex_unlock(&my_lock); I have the following piece of code in thread B, which signals thread A pthread_mutex_lock(&my_lock); testCondition = true; pthread_cond_signal(&my_wait); pthread_mutex_unlock(&my_lock); Provided there are no other threads, would it make any difference if pthread_cond_signal(&my_wait) is moved out of the critical section block as shown below ? pthread_mutex_lock(&my_lock);