-
Recent Posts
Recent Comments
Categories
Links
Daily Archives: July 17, 2017
wait on thread creation
下面的範例是一般worker thread的做法,利用boost threadgroup,在程式一開始由一個thread進入(main thread),離開的時候也是一個thread 一般來說在創建thread時不需要等待thread被創建完成再往下走,不過這裡示範了當所有thread建立完成後main thread才繼續往下執行(透過condition variable, wait) 這麼做可以讓控制流變的簡潔,並且視thread group的threads為一整體,也能確保在start()完成之前不會執行stop()。 ThreadManager.h #include #include #include #include #include class ThreadManager { std::mutex m; std::condition_variable cv; int numThreads = 5; //non-static data member with initializer (C++11) int startCount = 0; bool bRunning = … Continue reading
Posted in Tips
Leave a comment
warning C4819的處理
warning C4819: The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss 選擇 File>Advanced Save Options => Encoding: Unicode (UTF-8 with signature) – Codepage 65001 … Continue reading
Posted in Tips
Leave a comment