Monday, February 27, 2012

End of Synchronization

Finally finished my Operating Systems project on threads synchronization. Baboons are happily on the right sides. The  task was a "Baboons on two sides" problem with a FIFO order requirement. Used classic Readers/Writers solution for the baboons problem and conditions variables to ensure the FIFO order. After the assignment is done it seems so easy))))

By the way, if you are new to synchronization, then check Little Book of Semaphores. It is easy to read and has a lot of solutions to the classic synchronization problems. Although, it is not very high-technology. For example, it does not use conditional variables to guarantee the FIFO order. Instead, it uses tricky constructed queue, which is much harder.

Source code: https://docs.google.com/open?id=0B150EMF9ZCuUbVdtZUU2cW9TNnVQX1B4Yk9zbHRDUQ

Sunday, February 26, 2012

How to Port PThread-Win32

Finally got it!
  1. Put your .h files (pthread.h, semaphore.h, sched.h) into $Visual_Studio/VC/include.
  2. pthreadVC1.dll goes to C:/Windows. Not the best idea but I am out of time and this works.
  3. pthreadVC1.lib goes to $Visual_Studio/VC/lib. Also, include it in the Linker. Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies. Add there pthreadVC1.lib.
These actions should eliminate all external linking errors. Although, you may still have problems when you run the application. I got the error: pthreadVC1.dll missing. In this case, put pthreadVC1.dll into C:/Windows/SysWOW64 where all other dlls are (like kernel32.dll). Probably it is a better solution to start with.

Also, use Sleep() for Windows (add #include <Windows.h>) and sleep() (add #include <unistd.h>) for UNIX-based systems.