From: Paul H. Hargrove (PHHargrove_at_lbl.gov)
Date: Mon Oct 14 2002 - 13:01:37 PDT
Sriram et.al., The singal-safe spinlocks we discussed on the previous AG call are now in CVS. I'VE NOT YET TESTED ANY OF THIS. Below is the relavent stuff from libcr.h. For now the spinlock debugging is on by default because I might have messed something up. You'll need to edit libcr/cr_sig_sync.c to turn it off. If an error is detected (such as use of an uninitiallized spinlock or unlocking an unlocked spinlock) then error output will go to stderr. Unfortunately if this happens in signal context this output may itself corrupt the pthreads data structures or crash the process :-(. Of course that won't be a problem because such output only happens in buggy programs :-). If more complex synchronization mechanisms such as condition variables or semaphores are needed then we can discuss them. ALSO NOTE: Along with the addition of the reentrant spinlocks, I've checked in some unrelated code which has made changes to the user/kernel interface. You'll need to load an updated kernel module to use the updated libcr. -Paul // Type for signal-safe spinlocks typedef unsigned long cr_spinlock_t; // cr_spinlock_init() // // Initialize a spinlock (to the unlocked state). // This must be done before the first use. // // This routine is both thread-safe and reentrant (signal-safe). extern void cr_spinlock_init(cr_spinlock_t *); // cr_spinlock_lock() // // Spin (busy wait) until the lock can be obtained. // // This routine is both thread-safe and reentrant (signal-safe). extern void cr_spinlock_lock(cr_spinlock_t *); // cr_spinlock_unlock() // // Unlock a lock held by this process/thread. // // This routine is both thread-safe and reentrant (signal-safe). extern void cr_spinlock_unlock(cr_spinlock_t *); // cr_spinlock_trylock() // // Try only once to obtain a lock. // Returns non-zero if and only if the lock is obtained. // // This routine is both thread-safe and reentrant (signal-safe). extern int cr_spinlock_trylock(cr_spinlock_t *); -- Paul H. Hargrove PHHargrove_at_lbl_dot_gov Future Technologies Group HPC Research Department Tel: +1-510-495-2352 Lawrence Berkeley National Laboratory Fax: +1-510-495-2998