how to Write Multi-Threaded Code