我在读中断.可以通过特殊的中断屏蔽挂起非关键中断.这称为中断屏蔽.我不知道什么时候/为什么你可能想要或需要暂时暂停中断?可能是信号量,还是在多处理器环境中编程?
两者都会导致程序停止执行.但很明显,这种情况必然存在一些差异.这些是什么?
咨询的JavaDoc和的源代码Thread.interrupt()中的方法Java SE 7,我发现这个:
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();
Run Code Online (Sandbox Code Playgroud)
可以看出,本机方法调用位于//1同步块之外.那么,如果不将interrupt()方法调用到synchronized块中,是否安全?
Thread t;
//something else
t.interrupt(); //Not in a synchronized block
Run Code Online (Sandbox Code Playgroud)
它是线程安全的吗?如果超过1个线程试图同时中断它怎么办?interrupt0那么本机方法将如何表现?
如果ISR正在运行,会发生另一个中断,会发生什么?第一个中断是否被中断?第二个中断会被忽略吗?或者在第一次ISR完成后会发射吗?
编辑 我忘了将它包含在问题中(但我将其包含在标签中),我想问一下这是如何在Atmel AVR上运行的.
在Linux上,feenableexcept和fedisableexcept可用于控制浮点异常上SIGFPE中断的生成.如何在Mac OS X Intel上执行此操作?
用于启用浮点中断的内联汇编在http://developer.apple.com/documentation/Performance/Conceptual/Mac_OSX_Numerics/Mac_OSX_Numerics.pdf,第7-15页中提供,但仅适用于PowerPC汇编.
我知道双核CPU如何处理中断.我想知道如何在具有多个物理处理器的电路板上实现中断处理.
是否有任何中断责任由物理板的配置决定?每个处理器必须能够处理某些类型的中断,如磁盘I/O. 除非有一些电路来管理和分配适当的处理器中断?我的猜测是该方案必须是处理器中立的,因此任何处理器和内核都可以运行中断处理程序.
如果核心正在等待磁盘读取,那么当磁盘准备就绪时,该核心是否会运行中断处理程序?
我最近继承了一个几乎没有Thread安全性的大型Java应用程序.我目前正在努力的是让所有线程正确处理被中断而不是使用非常糟糕的Thread.stop().
问题的一部分是我不知道每个方法调用清除中断标志.
目前我知道以下将清除中断标志:
Thread.interrupted()
Thread.sleep(long)
Thread.join()
Thread.join(long)
Object.wait()
Object.wait(long)
Run Code Online (Sandbox Code Playgroud)
我还缺少什么?谢谢
我想知道我何时AVAudioRecorder无法进入(例如音乐开始播放时).
正如audioRecorderEndInterruption将在iOS 9中弃用的那样,我专注于AVAudioSession中断通知(但两者都没有按预期工作).
问题是,如果应用程序在中断发生时仍然在前台,则永远不会调用中断通知.
例如:用户启动和停止播放音乐而不将应用程序移动到后台.
要检测我正在使用的任何中断:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionWasInterrupted:) name:AVAudioSessionInterruptionNotification object:nil];
...
- (void)audioSessionWasInterrupted:(NSNotification *)notification {
if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
NSLog(@"Interruption notification");
if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
NSLog(@"InterruptionTypeBegan");
} else {
NSLog(@"InterruptionTypeEnded");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我InterruptionTypeBegan按预期得到了,但InterruptionTypeEnded如果应用程序仍在前台,则不会被调用(意味着在将应用程序放置在后台并返回到前台之前不会调用它).
InterruptionTypeEnded当应用程序在前台时发生中断时,我如何收到通知?
我有阻塞任务,将由find_the_question()函数执行.但是,我不希望线程执行此函数需要超过10秒.因此,如果它需要超过10秒,我想关闭该线程清理所有资源.
我尝试为此编写代码,但不知何故,如果线程占用时间超过10秒,我无法在find_the_question()函数中获得中断.你能告诉我我做错了什么吗?
void find_the_question(std::string value)
{
//allocate x resources
try{
//do some process on resources
sleep(14);
//clean resources
}
catch(boost::thread_interrupted const& )
{
//clean resources
std::cout << "Worker thread interrupted" << std::endl;
}
}
int main()
{
boost::posix_time::time_duration timeout = boost::posix_time::milliseconds(10000);
std::cout << "In main" << std::endl;
boost::thread t1(find_the_question, "Can you block me");
t1.interrupt();
if (t1.timed_join(timeout))
{
//finished
std::cout << "Worker thread finished" << std::endl;
}
else
{
//Not finished;
std::cout << "Worker thread not finished" << std::endl;
}
std::cout …Run Code Online (Sandbox Code Playgroud) interrupt ×10
java ×3
avfoundation ×1
avr ×1
boost-thread ×1
c++ ×1
cpu ×1
embedded ×1
exception ×1
hardware ×1
intel ×1
ios ×1
macos ×1
multicore ×1
terminology ×1