зеркало из https://github.com/mono/ikvm-fork.git
Another attempt to fix race conditions in Thread.interrupt().
This commit is contained in:
Родитель
d691f24a49
Коммит
faef699b6e
|
@ -3050,7 +3050,8 @@ namespace IKVM.NativeCode.java
|
||||||
internal Exception stillborn;
|
internal Exception stillborn;
|
||||||
internal bool running;
|
internal bool running;
|
||||||
private bool interruptPending;
|
private bool interruptPending;
|
||||||
private bool interruptableWait;
|
private volatile bool nativeInterruptPending;
|
||||||
|
private volatile bool interruptableWait;
|
||||||
private bool timedWait;
|
private bool timedWait;
|
||||||
|
|
||||||
#if !FIRST_PASS
|
#if !FIRST_PASS
|
||||||
|
@ -3127,15 +3128,16 @@ namespace IKVM.NativeCode.java
|
||||||
{
|
{
|
||||||
#if !FIRST_PASS
|
#if !FIRST_PASS
|
||||||
SystemThreadingThreadInterruptedException dotnetInterrupt = null;
|
SystemThreadingThreadInterruptedException dotnetInterrupt = null;
|
||||||
|
interruptableWait = false;
|
||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (this)
|
||||||
{
|
{
|
||||||
interruptableWait = false;
|
if (nativeInterruptPending)
|
||||||
if (interruptPending)
|
|
||||||
{
|
{
|
||||||
|
nativeInterruptPending = false;
|
||||||
// HACK if there is a pending Interrupt (on the .NET thread), we need to consume that
|
// HACK if there is a pending Interrupt (on the .NET thread), we need to consume that
|
||||||
// (if there was no contention on "lock (this)" above the interrupted state isn't checked)
|
// (if there was no contention on "lock (this)" above the interrupted state isn't checked)
|
||||||
try
|
try
|
||||||
|
@ -3149,6 +3151,9 @@ namespace IKVM.NativeCode.java
|
||||||
catch (SystemThreadingThreadInterruptedException)
|
catch (SystemThreadingThreadInterruptedException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (interruptPending)
|
||||||
|
{
|
||||||
interruptPending = false;
|
interruptPending = false;
|
||||||
throw new jlInterruptedException();
|
throw new jlInterruptedException();
|
||||||
}
|
}
|
||||||
|
@ -3158,6 +3163,7 @@ namespace IKVM.NativeCode.java
|
||||||
catch (SystemThreadingThreadInterruptedException x)
|
catch (SystemThreadingThreadInterruptedException x)
|
||||||
{
|
{
|
||||||
dotnetInterrupt = x;
|
dotnetInterrupt = x;
|
||||||
|
nativeInterruptPending = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dotnetInterrupt != null)
|
if (dotnetInterrupt != null)
|
||||||
|
@ -3171,10 +3177,14 @@ namespace IKVM.NativeCode.java
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (this)
|
||||||
{
|
{
|
||||||
interruptPending = true;
|
if (!interruptPending)
|
||||||
if (interruptableWait)
|
|
||||||
{
|
{
|
||||||
nativeThread.Interrupt();
|
interruptPending = true;
|
||||||
|
if (interruptableWait)
|
||||||
|
{
|
||||||
|
nativeInterruptPending = true;
|
||||||
|
nativeThread.Interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3434,6 +3444,9 @@ namespace IKVM.NativeCode.java
|
||||||
}
|
}
|
||||||
SystemThreadingThread.Sleep((int)(millis % int.MaxValue));
|
SystemThreadingThread.Sleep((int)(millis % int.MaxValue));
|
||||||
}
|
}
|
||||||
|
catch (SystemThreadingThreadInterruptedException)
|
||||||
|
{
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
t.LeaveInterruptableWait();
|
t.LeaveInterruptableWait();
|
||||||
|
@ -3688,6 +3701,9 @@ namespace IKVM.NativeCode.java
|
||||||
Monitor.Wait(o, new TimeSpan(timeout * 10000));
|
Monitor.Wait(o, new TimeSpan(timeout * 10000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (SystemThreadingThreadInterruptedException)
|
||||||
|
{
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
t.LeaveInterruptableWait();
|
t.LeaveInterruptableWait();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче