Implement semaphore extension.
Fix codes pointed in review.
Cosmetic changes.
Merge branch 'semaphore'