Skip to content

Commit

Permalink
thread.c: Add log message before calling pthread_cancel.
Browse files Browse the repository at this point in the history
Add a log message *before* calling pthread_cancel, so
if a deadlock occurs and this is possibly suspected to
be related to pthread_cancel usage, that can be confirmed
more easily from the logs (see LBBS-86).
  • Loading branch information
InterLinked1 committed Nov 30, 2024
1 parent 1789ec3 commit 74ee034
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bbs/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ int bbs_pthread_cancel_kill(pthread_t thread)
{
int res;

/* Log a message before calling pthread_cancel, since this is dangerous.
* In the unlikely event that a thread is cancelled while in a critical section,
* deadlock could ensue. I've suspected this might have been responsible for
* some issues in the past but few clues have been available to such activity,
* so this log message is an important clue if that happens (see [LBBS-86]). */
bbs_debug(1, "Attempting to cancel thread %lu\n", (unsigned long) thread);

#undef pthread_cancel
res = pthread_cancel(thread);
if (res) {
if (res == ESRCH) {
Expand Down
2 changes: 2 additions & 0 deletions include/bbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
#define ctime(a) Do_not_use_ctime__use_ctime_r
#define ptsname(fd) Do_not_use_ptsname__use_ptsname_r
#define strncpy(dest, src, size) Do_not_use_strncpy__use_safe_strncpy
/* Prohibit direct usage of dangerous functions */
#define pthread_cancel(t) Do_not_use_pthread_cancel__use_bbs_pthread_cancel_kill

#ifndef BBS_MAIN_FILE
/* Allow printf only in bbs.c */
Expand Down

0 comments on commit 74ee034

Please sign in to comment.