Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constrain signal delivery to Scheme to the main thread #813

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions c/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ EXTERN int S_num_preserve_ownership_threads;
# ifdef IMPLICIT_ATOMIC_AS_EXPLICIT
EXTERN s_thread_mutex_t S_implicit_mutex;
# endif
EXTERN s_thread_t S_main_thread_id;
#endif

/* segment.c */
Expand Down
10 changes: 10 additions & 0 deletions c/schsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,16 @@ ptr S_dequeue_scheme_signals(ptr tc) {
static void forward_signal_to_scheme(INT sig) {
ptr tc = get_thread_context();

#ifdef PTHREADS
/* deliver signals to the main thread, only; depending
on the threads that are running, `tc` might even be NULL */
if (tc != TO_PTR(&S_G.thread_context)) {
pthread_kill(S_main_thread_id, sig);
RESET_SIGNAL
return;
}
#endif

if (enqueue_scheme_signal(tc, sig)) {
SIGNALINTERRUPTPENDING(tc) = Strue;
SOMETHINGPENDING(tc) = Strue;
Expand Down
1 change: 1 addition & 0 deletions c/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void S_thread_init(void) {
s_thread_cond_init(&S_terminated_cond);
S_alloc_mutex.owner = 0;
S_alloc_mutex.count = 0;
S_main_thread_id = s_thread_self();

# ifdef IMPLICIT_ATOMIC_AS_EXPLICIT
s_thread_mutex_init(&S_implicit_mutex);
Expand Down
2 changes: 2 additions & 0 deletions csug/system.stex
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ After a signal handler for a given signal has been registered, receipt
of the specified signal results in a call to the handler.
The handler is passed the signal number, allowing the same handler to
be used for different signals while differentiating among them.
In a threaded version of the system, signals are always delivered to
the main thread.

Signals handled in this fashion are treated like keyboard interrupts in
that the handler is not called immediately when the signal is delivered
Expand Down