私は、文字列のベクトルを引数&として受け入れるライブラリを使って、それを文字列ベクトル(2Dベクトル)のベクトルにプッシュします。 私は、 "最初の行から2番目のベクトルにプッシュされ、タイマーは" X "ミリ秒ごとに&を開始する必要があるという条件があります。特殊文字列" FLAG_BORDER "を文字列のベクトルの最後に追加したい私は図書館に引数として受け取ること。C++でタイマーを繰り返し記録する
ライブラリコード
using namespace std;
vector<vector<sring>> vecOfVecStrs;
MyLibraryFunction(vector<string> vecstr)
{
if(TimerLimitNOTHit()) // THIS FUNCTION TimerLimitNOTHit() checks if the "X"
// th milisecond is reached or not.
{
vecOfVecStrs.push_back(vecstr); // If "X"th ms time poeriod is NOT
// yet reached
}
else
{
vecstr.push_back("FLAG_BORDER");
vecOfVecStrs.push_back(vecstr);
}
ライブラリ関数を呼び出すアプリケーションコード::
int main()
{
do_something();
vector<string> vecStr;
while(vecStr = Get_VecTor_of_strings())
{
MyLibraryFunction(vecStr);
}
ここでは、 は、C++の "MyLibraryFunction()"への関数呼び出しでタイマー "X"ミリ秒を追跡する必要がある、TimerLimitNOTHit()関数を実装しますか?
EDITED:回答が見つかりました。それは働くでしょうか?ここで
int timeX = 30; //s
bool keepTrack = false;
int ci = 0;
std::vector<int> timeArray;
std::mutex m;
bool keepTracking()
{
std::unique_lock<std::mutex> lock(m);
return keepTrack;
}
void GlobalTimer()
{
while (keepTracking())
{
std::this_thread::sleep_for(std::chrono::seconds(timeX));
timeArray[ci] = 1;
}
}
std::thread t1(GlobalTimer);
コードをインデントしてください。 –