|
101 | 101 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
102 | 102 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
103 | 103 | import com.oracle.truffle.api.ContextThreadLocal;
|
| 104 | +import com.oracle.truffle.api.ThreadLocalAction; |
104 | 105 | import com.oracle.truffle.api.Truffle;
|
105 | 106 | import com.oracle.truffle.api.TruffleFile;
|
106 | 107 | import com.oracle.truffle.api.TruffleLanguage;
|
@@ -1154,7 +1155,12 @@ private void joinThreads() {
|
1154 | 1155 | // in the acquireGil function, which will be interrupted for these threads
|
1155 | 1156 | disposeThread(thread);
|
1156 | 1157 | for (int i = 0; i < 100 && thread.isAlive(); i++) {
|
1157 |
| - thread.interrupt(); |
| 1158 | + env.submitThreadLocal(new Thread[]{thread}, new ThreadLocalAction(true, false) { |
| 1159 | + @Override |
| 1160 | + protected void perform(ThreadLocalAction.Access access) { |
| 1161 | + throw new PythonThreadKillException(); |
| 1162 | + } |
| 1163 | + }); |
1158 | 1164 | thread.join(2);
|
1159 | 1165 | }
|
1160 | 1166 | if (thread.isAlive()) {
|
@@ -1263,25 +1269,10 @@ boolean tryAcquireGil() {
|
1263 | 1269 | @TruffleBoundary
|
1264 | 1270 | void acquireGil() throws InterruptedException {
|
1265 | 1271 | assert !ownsGil() : dumpStackOnAssertionHelper("trying to acquire the GIL more than once");
|
1266 |
| - try { |
1267 |
| - globalInterpreterLock.lockInterruptibly(); |
1268 |
| - } catch (InterruptedException e) { |
1269 |
| - if (!ImageInfo.inImageBuildtimeCode() && getThreadState(getLanguage()).isShuttingDown()) { |
1270 |
| - // This is a thread being killed during normal context shutdown. This thread |
1271 |
| - // should exit now. This should usually only happen for daemon threads on |
1272 |
| - // context shutdown. This is the equivalent to the logic in pylifecycle.c and |
1273 |
| - // PyEval_RestoreThread which, on Python shutdown, will join non-daemon threads |
1274 |
| - // and then simply start destroying the thread states of remaining threads. If |
1275 |
| - // any remaining daemon thread then tries to acquire the GIL, it'll notice the |
1276 |
| - // shutdown is happening and exit. |
1277 |
| - throw new PythonThreadKillException(); |
1278 |
| - } else { |
1279 |
| - // We are being interrupted through some non-internal means. Commonly this may be |
1280 |
| - // because Truffle wants to run some safepoint action. In this case, we need to |
1281 |
| - // rethrow the InterruptedException. |
1282 |
| - Thread.interrupted(); |
1283 |
| - throw e; |
1284 |
| - } |
| 1272 | + boolean wasInterrupted = Thread.interrupted(); |
| 1273 | + globalInterpreterLock.lockInterruptibly(); |
| 1274 | + if (wasInterrupted) { |
| 1275 | + Thread.currentThread().interrupt(); |
1285 | 1276 | }
|
1286 | 1277 | }
|
1287 | 1278 |
|
|
0 commit comments