interrupted-exception

epoll_wait fails due to EINTR, how to remedy this?

余生颓废 提交于 2019-12-05 23:39:47
My epoll_wait fails due to EINTR. My gdb trace shows this: enter code here 221 in ../nptl/sysdeps/pthread/createthread.c (gdb) 224 in ../nptl/sysdeps/pthread/createthread.c (gdb) [New Thread 0x40988490 (LWP 3589)] 227 in ../nptl/sysdeps/pthread/createthread.c (gdb) epoll_wait error in start timer: Measurement will befor entire duration of execution epoll_wait: Interrupted system call [Thread 0x40988490 (LWP 3589) exited] This string "epoll_wait error in start timer: Measurement will befor entire duration of execution" is printed by me in stderr. I am not able to make out, how to remedy this

Does Thread.sleep throw if the thread was already interrupted?

删除回忆录丶 提交于 2019-12-05 11:46:35
Given a thread which was interrupted while it was not blocked (i.e. no InterruptedException was thrown), does that thread throw an InterruptedException when it later attempts to sleep? The documentation does not state this clearly: InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown. Yes, it does. The documentation perhaps isn't crystal clear on that point, but this is easy to both test (see the your own answer below, for example), and to see the canonical (HotSpot) implementation. Thread

Interrupted exception vs isInterrupted in a while loop

a 夏天 提交于 2019-12-05 04:36:28
问题 Assume that I have the following code: while(!Thread.currentThread().isInterrupted()){ //do something Thread.sleep(5000); } Now Thread.sleep throws `InterruptedException so it should be like this: while(!Thread.currentThread().isInterrupted()){ //do something try{ Thread.sleep(5000); } catch(InterruptedException e){ } } If I hit the catch will the while loop continue or do I need to do Thread.currentThread().interrupt() ? If I do call this method, won't that also cause an InterruptedException

When to use Interrupt Gate or Trap Gate?

混江龙づ霸主 提交于 2019-12-04 19:18:50
As the Intel Manual illustrated, both Interrupt Gate and Trap Gate can be used to access a handler routine. And some exceptions even share vector numbers with interrupts. I am wondering when such a shared vector is detected by the CPU, how could CPU know whether it stands for an exception or an interrupt? I am kind of confused about the logic among the following things: the decision of the gate types in the IDT the judgement of whether the vector stands for an exception or an interrupt Which decides which? I hope I made myself clear... Update 1 Thanks for nos' reply. Do you mean I have to tell

Handling InterruptedException while waiting for an exit signal (bug in Android?)

陌路散爱 提交于 2019-12-04 19:13:54
问题 I've come across the code below, and I'm wondering if it does exactly what I think it does: synchronized(sObject) { mShouldExit = true; sObject.notifyAll() while (!mExited) { try { sObject.wait(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } About the context: there is another thread that checks for mShouldExit (inside the sObject monitor) and will exit in that case. This does not look to be a correct pattern to me. If an interrupt happens, it will set the

How to handle dispose in RxJava without InterruptedException

两盒软妹~` 提交于 2019-12-04 18:08:21
In the below code snipped when dispose() is called, then the emitter thread is interrupted ( InterruptedException is thrown out of sleep method). Observable<Integer> obs = Observable.create(emitter -> { for (int i = 0; i < 10; i++) { if (emitter.isDisposed()) { System.out.println("> exiting."); emitter.onComplete(); return; } emitter.onNext(i); System.out.println("> calculation = " + i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } emitter.onComplete(); }); Disposable disposable = obs .subscribeOn(Schedulers.computation()) .subscribe(System.out::println

Under what conditions will BlockingQueue.take throw interrupted exception?

狂风中的少年 提交于 2019-12-03 13:56:59
Let us suppose that I have a thread that consumes items produced by another thread. Its run method is as follows, with inQueue being a BlockingQueue boolean shutdown = false; while (!shutdown) { try { WorkItem w = inQueue.take(); w.consume(); } catch (InterruptedException e) { shutdown = true; } } Furthermore, a different thread will signal that there are no more work items by interrupting this running thread. Will take() throw an interrupted exception if it does not need to block to retrieve the next work item. i.e. if the producer signals that it is done filling the work queue, is it

Handling InterruptedException while waiting for an exit signal (bug in Android?)

旧时模样 提交于 2019-12-03 12:24:17
I've come across the code below, and I'm wondering if it does exactly what I think it does: synchronized(sObject) { mShouldExit = true; sObject.notifyAll() while (!mExited) { try { sObject.wait(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } About the context: there is another thread that checks for mShouldExit (inside the sObject monitor) and will exit in that case. This does not look to be a correct pattern to me. If an interrupt happens, it will set the interrupted status again, so when it returns to sObject.wait() , another InterruptedException will come

LinkedBlockingQueue thowing InterruptedException

不想你离开。 提交于 2019-12-02 12:27:37
I have this piece of code. A LinkedBlockingQueue should only throw an Exception if interrupted while waiting to add to the queue. But this queue is unbounded so it should add asap. Why does my shutdown methode throw an InterruptedException ? private final LinkedBlockingQueue<Message> messages= new LinkedBlockingQueue<Message>(); public void run(){ LinkedList<Message> messages = new LinkedList<Message>(); while (true){ try{ messages.clear(); messages.add(this.messages.take()); this.messages.drainTo(messages); for (Message message:messages){ if(message.isPoison())return; doSomething(message); }

Thread with Lambda expression

*爱你&永不变心* 提交于 2019-11-30 18:21:51
I have an error at line 42 and 43 : Thread t1=new Thread(()->prod.test()); , Thread t2=new Thread(()->cons.test()); Unhandled exception type InterruptedException . If I try to quickfix it will created the try catch with an catch Exception , it will have the same error and will try to fix it in the same way continuing to surround it with try catch. import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; interface Predicate { public void test() throws InterruptedException; } class MyClass { int num = 0; Lock lock = new ReentrantLock(); public void produce()