Skip to content

Commit

Permalink
i#2157 re-attach: Add timeout to os_thread_suspend
Browse files Browse the repository at this point in the history
After 5 seconds of waiting for a thread to acknowledge a received
signal, os_thread_suspend now returns false so that the caller can
retry.

Issue #2157
  • Loading branch information
Carrotman42 committed Dec 13, 2017
1 parent 832e148 commit 8d81ca6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/synch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1922,10 +1922,10 @@ detach_on_permanent_stack(bool internal, bool do_cleanup)
DEBUG_DECLARE(bool ok;)
DEBUG_DECLARE(int exit_res;)
/* synch-all flags: if we fail to suspend a thread (e.g., privilege
* problems) ignore it. XXX Should we retry instead?
* problems) retry it.
*/
/* i#297: we only synch client threads after process exit event. */
uint flags = THREAD_SYNCH_SUSPEND_FAILURE_IGNORE | THREAD_SYNCH_SKIP_CLIENT_THREAD;
uint flags = THREAD_SYNCH_SUSPEND_FAILURE_RETRY | THREAD_SYNCH_SKIP_CLIENT_THREAD;

ENTERING_DR();

Expand Down
13 changes: 10 additions & 3 deletions core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -3474,10 +3474,17 @@ os_thread_suspend(thread_record_t *tr)
*/
mutex_unlock(&ostd->suspend_lock);
while (ksynch_get_value(&ostd->suspended) == 0) {
/* For Linux, waits only if the suspended flag is not set as 1. Return value
* doesn't matter because the flag will be re-checked.
/* For Linux, waits only if the suspended flag is not set as 1. Other
* than a timeout value, the return value doesn't matter because the
* flag will be re-checked.
*/
ksynch_wait(&ostd->suspended, 0, 0);
if (ksynch_wait(&ostd->suspended, 0, 5000) == -ETIMEDOUT) {
mutex_lock(&ostd->suspend_lock);
ASSERT(ostd->suspend_count > 0);
ostd->suspend_count--;
mutex_unlock(&ostd->suspend_lock);
return false;
}
if (ksynch_get_value(&ostd->suspended) == 0) {
/* If it still has to wait, give up the cpu. */
os_thread_yield();
Expand Down

0 comments on commit 8d81ca6

Please sign in to comment.