interrupt

How should I close a socket in a signal handler?

醉酒当歌 提交于 2019-12-01 16:13:05
I'm writing a very simple server that loops forever until Ctrl-C is pressed. I'd like to have the signal handler for ctrl-c close the open sockets and shut down the server, but I don't know what the scope is for a signal handler, and I don't like the idea of declaring the socket(s) I would need to close to be global. Can someone offer suggestions? Is there some standard way to do this? Well, since you have signal handlers, I'm going to assume you're on a Unix variant. If so: A socket is identified to the kernel by the file number, which is an int. See socket(2) . That int is valid for your

How should I close a socket in a signal handler?

旧城冷巷雨未停 提交于 2019-12-01 15:52:14
问题 I'm writing a very simple server that loops forever until Ctrl-C is pressed. I'd like to have the signal handler for ctrl-c close the open sockets and shut down the server, but I don't know what the scope is for a signal handler, and I don't like the idea of declaring the socket(s) I would need to close to be global. Can someone offer suggestions? Is there some standard way to do this? 回答1: Well, since you have signal handlers, I'm going to assume you're on a Unix variant. If so: A socket is

Java equivalent of setInterval in javascript

白昼怎懂夜的黑 提交于 2019-12-01 15:09:11
Basically I want a function to be called every say, 10 milliseconds. How can I achieve that in Java? You might want to take a look at Timer . Check out java.util.Timer http://java.sun.com/javase/6/docs/api/java/util/Timer.html You could also use a ScheduleExecutorService. I would say you would create a thread and in the thread loop add a System.sleep(10) to make the thread "sleep" for 10 ms before continuing. 来源: https://stackoverflow.com/questions/652389/java-equivalent-of-setinterval-in-javascript

Do I need to synchronize a call to the interrupt method?

让人想犯罪 __ 提交于 2019-12-01 14:58:54
Consulting the JavaDocs and the source code of the Thread.interrupt() method in Java SE 7 I found this: public void interrupt() { if (this != Thread.currentThread()) checkAccess(); synchronized (blockerLock) { Interruptible b = blocker; if (b != null) { interrupt0(); // Just to set the interrupt flag b.interrupt(this); return; } } interrupt0(); //1, Outside of the synchronized block } //... private native void interrupt0(); As can be seen, the native method invocation at //1 is outside of the synchronized block. So, is it safe if don't put a call to the interrupt() method into a synchronized

Java equivalent of setInterval in javascript

混江龙づ霸主 提交于 2019-12-01 14:46:32
问题 Basically I want a function to be called every say, 10 milliseconds. How can I achieve that in Java? 回答1: You might want to take a look at Timer. 回答2: Check out java.util.Timer http://java.sun.com/javase/6/docs/api/java/util/Timer.html 回答3: You could also use a ScheduleExecutorService. 回答4: I would say you would create a thread and in the thread loop add a System.sleep(10) to make the thread "sleep" for 10 ms before continuing. 来源: https://stackoverflow.com/questions/652389/java-equivalent-of

Arduino interrupt alternatives

假装没事ソ 提交于 2019-12-01 14:10:25
From what I've read, the solution to my problem is to use an interrupt, but if I understand them correctly, I can't use a delay in the routine that gets called by the interrupt. I've got a large pushbutton LED switch. I want it to have a heartbeat while sitting idle, but once it's pushed, stay green and execute code. I can break the heartbeat() if I push the button enough times (I assume getting the state change at just the right time as it finishes a loop of the heartbeat ), but I'm stuck on how to make it work on the first click. Is there an alternative way to do what I'm attempting? void

Do I need to synchronize a call to the interrupt method?

╄→гoц情女王★ 提交于 2019-12-01 13:46:13
问题 Consulting the JavaDocs and the source code of the Thread.interrupt() method in Java SE 7 I found this: public void interrupt() { if (this != Thread.currentThread()) checkAccess(); synchronized (blockerLock) { Interruptible b = blocker; if (b != null) { interrupt0(); // Just to set the interrupt flag b.interrupt(this); return; } } interrupt0(); //1, Outside of the synchronized block } //... private native void interrupt0(); As can be seen, the native method invocation at //1 is outside of the

Arduino interrupt alternatives

此生再无相见时 提交于 2019-12-01 12:31:35
问题 From what I've read, the solution to my problem is to use an interrupt, but if I understand them correctly, I can't use a delay in the routine that gets called by the interrupt. I've got a large pushbutton LED switch. I want it to have a heartbeat while sitting idle, but once it's pushed, stay green and execute code. I can break the heartbeat() if I push the button enough times (I assume getting the state change at just the right time as it finishes a loop of the heartbeat ), but I'm stuck on

8086 assembly right mouse click interrupts

陌路散爱 提交于 2019-12-01 12:10:41
I am working on a project in 8086 assembly on windows machine and I need to know which mouse button has been clicked. What are the interrupts for this? or how do I go about finding this out? Thanks matja If you're making a DOS program that runs under windows, you can use software interrupt 0x33, function 3, which returns the button status in the BL register : mov ax,0x3 int 0x33 test bl,1 jnz left_button_pressed test bl,2 jnz right_button_pressed More info here http://www.ctyme.com/intr/rb-5959.htm If you're making a native Windows application, you can test for button presses by checking for

How SCI - System Control Interrupt vector is defined?

孤街醉人 提交于 2019-12-01 11:53:52
问题 According to the ACPI spec, The FADT (Fixed ACPI Description Table) table contains a field that reports the SCI interrupt number to OS. The field is defined as below: I dumped the FADT table on an Intel x86 platform and see the SCI interrupt is associated with the number 9 : But according to the Intel Manual, 0-31 are reserved vectors for IA architecturally defined interrupts. Specifically, the 9 is defined as: So, according to the note, the 9 is not generated after I386 processor. So I guess