http://www.acm.uiuc.edu/sigops/roll_your_own/

try this