Moved the swap of the buffers before the pthread_join

Signed-off-by: Riccardo Binetti <punkerbino@gmail.com>