88d Subj : Re: Windows Suspend/ResumeThread API equivalent for Linux or POSIX? To : comp.programming.threads From : Chris Thomasson Date : Wed May 11 2005 07:12 pm >> In order to call the Windows GetThreadContext Thread API, you need to use >> the Resume/SuspendThread API. I am reading thread context and comparing >> against deferred pointers in a modified SMR polling algorithm; You can >> eliminate the hazard pointer reload and compare by doing this. > > Sounds like doing an awful lot of work to save a small amount of work. :) > Suspending a thread without its cooperation is an incredibly expensive > thing to do. Yes. Luckily, the algorithm assumes that. The polling algorithm in question only runs about every five seconds, or when the total number of deferred objects hits a certain level, its usually set to about a half-million nodes. This is sufficient for many "read-mostly" data structures. Using thread context for an algorithm that had a moderate and somewhat persistent number of writes would be way too expensive. Anyway, I am not really advocating scanning thread context to implement SMR. I want to gather a number of different somewhat portable methods together so I can show how my new algorithm differs from each one. >> I was wondering if Linux and/or POSIX has a way to get thread context and >> if it was similar to the way windows does it. Something like: >> >> pthread_suspend_np( pthread_t, ucontext_t* ); >> pthread_resume_np( pthread_t ); > > No. Ok. How about any Linux specific function to grab a copy of a thread's context? I am not a Linux Kernel guru. > What could you do while the thread was suspended? > How can you be sure you don't trip over a lock the suspended thread holds? Yes, this can be so dangerous... Microsoft recommends that the thread that calls SuspendThread API not hold and/or access "any" sync objects: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/suspendthread.asp If you can't guarantee this with 100% certainty, then using SuspendThread is like playing with a lit stick of dynamite. :) . 0