1
下面是一些代码,我有atm。你可以选择线程池中的线程来执行(boost)
int main()
{
boost::thread_group threads; // Thread Pool
// Here we create threads and kick them off by passing
// the address of the function to call
for (int i = 0; i < num_threads; i++)
threads.create_thread(&SendDataToFile);
threads.join_all();
system("PAUSE");
}
void SendDataToFile()
{
// The lock guard will make sure only one thread (client)
// will access this application at once
boost::lock_guard<boost::mutex> lock(io_mutex);
for (int i = 0; i < 5; i++)
cout << "Writing" << boost::this_thread::get_id() << endl;
}
此刻我只是使用cout而不是写入文件。
是否有可能在另一个线程之前实际选择一个线程来执行操作。所以我有一个我想要写入的文件,4个线程想要同时访问该文件,是否有可能让我先说第2个线程。 ? in BOOST
fstream可以像cout一样使用吗?当我写入文件的输出不是混乱的(没有互斥)?但是当我打印到没有互斥体的控制台时,就像你期望的那样很麻烦。
链接可能会有所帮助http://en.wikipedia.org/wiki/Scheduling_%28computing%29 – user2202911 2015-01-21 10:27:16
@ user2202911有没有关于此的任何提升示例? – CodersSC 2015-01-21 10:42:07
我不知道任何 - 对不起。 – user2202911 2015-01-21 10:47:43