Hey i think problem lies here,
int main()
{
_beginthread(wr_thread, 0, NULL );
_beginthread(rd_thread, 0, NULL );
cin>>ip;
return(0);
}
You are creating two threads and you are returning from the main thread with out waiting for the child threads to do there work.Check this link& example for _beginthread()
http://msdn.microsoft.com/en-us/library/kdzttdcb.aspx[
^]
Also you have to synchronize the threads when you are sharing same resources.