organize code header, fix threads sync bugs

1. add some header files; 2. fix the bug that when receiver thread exit,
the kernel crashes.