[Gc] Attaching and dettaching existing threads

C. Scott Ananian C. Scott Ananian" <cscott@cscott.net
Tue, 14 Oct 2003 10:33:46 -0400 (EDT)

On Tue, 14 Oct 2003, David Bakin wrote:

> (*) Actually, I just thought of another possibility that I haven't tried and
> I haven't seen described anywhere.  So that probably means it doesn't work.
> But if it does work it would mean you don't need to have your worker threads
> poll an event, and you could safely kill any thread.  You SuspendThread the
> thread you want to kill, GetThreadContext to get its machine registers, set
> the IP to a routine that calls ExitThread (the only safe way to exit a
> thread) or just point IP to the real ExitThread routine, SetThreadContext,
> ResumeThread.

This may release your locks, but it still doesn't guarantee that your data
structures are in a consistent state.  You need non-blocking
synchronization instead of mutexes, or else a transactional memory system
if you want consistency.
[The Real-Time Java specification has another approach to the problem:
routines can be specially marked interruptible (which
basically means that data structures are in a consistent state at those
points).  Throwing an asynchronous exception to a thread results in the
exception being delayed until such a "safe point" is reached.  Slightly
safer, but you're still vulnerable to a thread which takes a lock, frobs a
shared data structure in a dangerous way, and then infinite loops.]

AES Seattle hack plutonium munitions security Mossad Albanian $400 million in gold bullion 
affinity group FSF Richard Tomlinson PLO KGB Justice Leitrim corporate globalization 
                         ( http://cscott.net/ )