separate input and output codes into two threads