Added critical sections for pthreads-library. Thanks to Ian Ibbotson,