gpushd-server: Avoid a race condition

This patch avoids a race condition when cleaning a specific thread. The
call to close was not protected in a critical section.