Summary: | False positives when using sem_trywait | ||
---|---|---|---|
Product: | [Developer tools] valgrind | Reporter: | jmcgee01125 |
Component: | helgrind | Assignee: | Paul Floyd <pjfloyd> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | pjfloyd |
Priority: | NOR | ||
Version: | 3.22.0 | ||
Target Milestone: | --- | ||
Platform: | Ubuntu | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
jmcgee01125
2024-03-25 21:16:29 UTC
If I add a pthread_join then I get no error. pthread_join only silences the warning if done before reading the shared state. In that case, the semaphore becomes useless (since pthread_join becomes the synchronization point). If joined after printing, like when synchronizing between two long-running threads, then this warning appears. Comment in hg_intercepts.c Unhandled: int sem_trywait(sem_t *sem); int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict abs_timeout); I looked at DRD, it just does the same thing as sem_wait so I tried this code on FreeBSD __attribute__((noinline)) static int sem_trywait_WRK(sem_t* sem) { OrigFn fn; int ret; VALGRIND_GET_ORIG_FN(fn); if (TRACE_SEM_FNS) { fprintf(stderr, "<< sem_trywait(%p) ", sem); fflush(stderr); } DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_WAIT_PRE, sem_t*,sem); CALL_FN_W_W(ret, fn, sem); DO_CREQ_v_WW(_VG_USERREQ__HG_POSIX_SEM_WAIT_POST, sem_t*,sem, long, (ret == 0) ? True : False); if (ret != 0) { DO_PthAPIerror( "sem_trywait", SEM_ERROR ); } if (TRACE_SEM_FNS) { fprintf(stderr, " sem_trywait -> %d >>\n", ret); fflush(stderr); } return ret; } #if defined(VGO_freebsd) LIBC_FUNC(int, semZutrywait, sem_t* sem) { /* sem_trywait */ return sem_trywait_WRK(sem); } #endif and it seems to work. I'll clean the code up (and add sem_timedwait) sometime this weekend. commit 485cea48a38db8db608bdaff0c695ff50bbe16b5 (HEAD -> master, origin/users/paulf/try-bug484480, origin/master, origin/HEAD, bug484480) Author: Paul Floyd <pjfloyd@wanadoo.fr> Date: Sat Mar 30 16:31:12 2024 +0100 Bug 484480 - False positives when using sem_trywait |