Fix GCC 11 gthr-amigaos-native thread cleanup and I/O inheritance - #47
Open
derfsss wants to merge 1 commit into
Open
Fix GCC 11 gthr-amigaos-native thread cleanup and I/O inheritance#47derfsss wants to merge 1 commit into
derfsss wants to merge 1 commit into
Conversation
Fix two issues in GCC's native AmigaOS thread implementation (libgcc/gthr-amigaos-native.c): 1. Thread process cleanup on program exit: Add __attribute__((destructor)) that waits for all threads created via __gthread_create to finish before the program exits. A 5-second per-thread timeout prevents hanging if a thread is blocked. After the timeout, DOS's NP_Child mechanism provides a safety net. Without this fix, child processes linger indefinitely after exit, leaking memory and triggering "Parent process has tried to exit before all children have" warnings from the shell. Affects all C++ programs using std::thread, std::async, std::future. 2. I/O handle inheritance: Change child thread processes to use NP_Input/NP_Output/NP_Error=ZERO instead of inheriting parent's file handles. Prevents "input fh buffer was changed" DOS warnings when parent exits first. Tested: 6/6 thread tests pass on AmigaOS 4.1 (Pegasos II via QEMU). Affected versions: GCC 8, 9, 10, 11 (all with amigaos thread model). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new GCC 11 patch intended to improve the AmigaOS native gthread implementation by ensuring child thread processes don’t linger on program exit and by preventing child threads from inheriting the parent’s I/O handles.
Changes:
- Introduces a destructor-based cleanup routine to wait (with timeout) for threads created via
__gthread_createbefore exit. - Changes
CreateNewProcTagsto useNP_Input/NP_Output/NP_Error = ZEROto avoid inheriting parent file handles. - Adds
__gthread_once_unlockimplementation (but this duplicates an existing patch in the current GCC 11 patch stack).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+46
to
+59
| @@ -194,6 +194,12 @@ | ||
| return 0; | ||
| } | ||
|
|
||
| +void __gthread_once_unlock(__gthread_once_t *__once) | ||
| +{ | ||
| + __internal_gthread_once_t *once = (__internal_gthread_once_t *)__once; | ||
| + __atomic_store_1(&once->u.i.started, 0, __ATOMIC_SEQ_CST); | ||
| +} | ||
| + | ||
| /******************************************************************************/ | ||
|
|
||
| /* We keep the entries of each key organized as a single linked list */ | ||
| @@ -541,6 +547,67 @@ |
Comment on lines
+1
to
+3
| From: Richard Gibbs <rich_gibbs@hotmail.com> | ||
| Date: Thu, 10 Apr 2026 15:00:00 +0100 | ||
| Subject: [PATCH] Fix gthr-amigaos-native thread cleanup and I/O inheritance |
Comment on lines
+1
to
+5
| From: Richard Gibbs <rich_gibbs@hotmail.com> | ||
| Date: Thu, 10 Apr 2026 15:00:00 +0100 | ||
| Subject: [PATCH] Fix gthr-amigaos-native thread cleanup and I/O inheritance | ||
|
|
||
| Fix two issues in the native AmigaOS thread implementation: |
|
@derfsss How can this be tested? Do you have any failing example that can be used to test the before and after status? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix two issues in GCC's native AmigaOS thread implementation (libgcc/gthr-amigaos-native.c):
Thread process cleanup on program exit: Add attribute((destructor)) that waits for all threads created via __gthread_create to finish before the program exits. A 5-second per-thread timeout prevents hanging if a thread is blocked. After the timeout, DOS's NP_Child mechanism provides a safety net.
Without this fix, child processes linger indefinitely after exit, leaking memory and triggering "Parent process has tried to exit before all children have" warnings from the shell.
Affects all C++ programs using std::thread, std::async, std::future.
I/O handle inheritance: Change child thread processes to use NP_Input/NP_Output/NP_Error=ZERO instead of inheriting parent's file handles. Prevents "input fh buffer was changed" DOS warnings when parent exits first.
Tested: 6/6 thread tests pass on AmigaOS 4.1 (Pegasos II via QEMU).
Affected versions: GCC 8, 9, 10, 11 (all with amigaos thread model).