software and hardware C-language locking algorithms and implementations