|
From: Josef W. <Jos...@gm...> - 2005-06-01 14:59:48
|
On Wednesday 01 June 2005 00:16, you wrote: > Josef Weidendorfer wrote: > In general, signals do not explicitly cause thread context switches. A > thread may become runnable because it received a signal, but it is no > different from any other reason a thread may become runnable (like a > syscall unblocking). Likewise, returning from a signal doesn't > explicitly cause a thread context switch. > > A signal handler isn't special in any way, so there's always a chance > you can get a context switch in a signal handler. > > What problem are you seeing? In my tool, I have global pointers to per-thread data structures. These pointers need to be updated on a thread context switch. I track context switches via callbacks SK_(thread_run)(ThreadId tid) and SK_(pre_deliver_signal)(ThreadId tid, ...) for switches before entering a signal handler. Now I have a bug report with an assertion because my data structures are getting corrupted. Looking at it, I see that there is an signal handler switching thread via SK_(pre_deliver_signal)(ThreadId tid, ...), and on returning, the previous running thread seems to be resumed, but I do not get any callback (e.g. via thread_run) that there is a thread context switch after the signal handler. If I restore the thread context which has executed before the signal handler, the assertion is gone for a small test case, but not for a more complex one. So this is no general solution if there can be context switches in a signal handler. The thing I need is a SK_(thread_run) callback after the signal handler if thread contexts are switching, and this is missing currently. I.e. it would be good to be able to track the current TID always via callbacks. But I need a solution which works with current VG releases. Perhaps setting the tracked TID to 0 after a signal handler is finished would be a possibility. Then, before any per-thread structure is accessed, the actual TID is looked up lazily via VG_(get_current_or_recent_tid)(), and the global pointers are corrected accordingly. Or accessing all per-thread data always via indirection, calling VG_(get_current_or_recent_tid)() everytime. I assume this will give some performance hit. Josef |