[問題] thread跟stdin stdout & termios.h

作者: sr29 (owo)   2015-06-24 12:01:12
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
termios.h
thread
unistd.h
問題(Question):
我宣告了兩個thread物件
第一個不斷的輸出printf("1");
第二個則是用自定義的getch()去監看輸入狀況
如果輸入a則停止程式、其餘的則輸出按下的值然後程式繼續
但是執行出來程式的output會卡在getch前
直到getch讀取到值以後才會把之前的output全部print出來
想問要如何做才能讓他不要等input......
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
http://paste.plurk.com/show/2192424/
補充說明(Supplement):
剛接觸thread如有觀念不對的地方
還請各位指教!
感謝大家m(_ _)m
作者: PkmX (阿貓)   2015-06-24 13:24:00
std::cout << std::flush;
作者: sr29 (owo)   2015-06-24 15:05:00
成功了O_O!!感謝!!!

Links booklink

Contact Us: admin [ a t ] ucptt.com