UINT -> UINT8 for oldPos/newPos, they're being cast later anyway.
Style consistency.
Simplify condition.
Free unused memory blocks.
Merge pull request #3 from RaMMicHaeL/pr2

A couple of other improvements
Fixed a condition of do-while.
Reintroduced spin lock.
I'm not sure that it works fine. So it needs through tests.
Changed SwitchToThread() to Sleep(0). It can allow threads on other processors to run.
Use Sleep(1) instead of Sleep(0).
Small changes in style.