From: Kalyanov D. <kal...@gm...> - 2010-10-26 19:30:10
|
Hello, I'd like to get review of support for Windows threads. Threading support is in 'windows-threads' branch of git://github.com/dmitryvk/sbcl-win32-threads.git repository, and the full diff of changes can be seen at http://github.com/dmitryvk/sbcl-win32-threads/compare/0c407...9523d Short summary of changes: 1) Subset of pthreads is implemented using win32 API. 2) Thread-local storage is implemented using an "Arbitrary data slot" in Thread Information Block (which is specific for a thread and is accessible via the FS register). 3) Instead of using signals to stop threads for GC and to interrupt threads, 'safepoints' and 'safe regions'[1] are used. Safepoint is a place in a code when threads checks if it should do something unusual: suspend for GC or handle an interruption. Safepoints are placed at heads of functions and loops (I'm not very proficient with SBCL compiler internals so I took Paul Khuong's code[2][3] for placement of safepoints). Safe region is a region of code when Lisp code is not running for a long period of time (safe regions are placed around foreign calls and possibly blocking code in C runtime). 4) Changed thread state transitions and thread state invariants. New thread state variables are added: * *disable-safepoints* is bound to T when thread can not be interrupted * *in-safepoint* is bound to T when thread executes the 'safepoint' routine to prevent infinite recursion * *gc-safe* is bound to T when thread leaves lisp code (it's safe not to wait for such thread to suspend for gc - it won't touch the memory) 5) GC gets thread context directly with SuspensThread/GetThreadContext/ResumeThread - not from saved interrupt context. It must be noted that despite threads are working they are not yet very useful on Windows because SBCL and other Lisp software like SLIME and usocket do not handle all issues that arise from threads (mostly related to Windows I/O). [1] http://xiao-feng.blogspot.com/2008/01/gc-safe-point-and-safe-region.html describes a very similar scheme [2] http://repo.or.cz/w/sbcl/pkhuong.git/shortlog/refs/heads/gc-safe-points [3] http://www.pvk.ca/Blog/LowLevel/VM_tricks_safepoints.html |