FLY
Life is like riding a bicycle, to keep your balance, you must keep moving.
摘要: 源代码:<1> 1 public static int Main() 2 { 3 Alpha oAlpha = new Alpha(); 4 5 Thread Thread1 = new Thread(delegate() { 6 Console.WriteLine("A"); 7 }); 8 Thread1.Start(); 9 Console.WriteLine("a");10 return 0;11 }<2>public static int... 阅读全文
posted @ 2012-11-29 16:23 juice_li 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 头文件:#include <thread>启动线程: 1.函数参数:1 void do_work();2 std::thread t(do_work); 2.对象参数:1 class do_work { 2 public: 3 void operator()(); 4 }; 5 do_work dw; 6 std::thread t(dw); 注意这里只是传了一个对象的拷贝进去。如果想传递对象本身(你应该确保在线程结束前它没有被销毁),可以使用std::ref。 do_work dw; std::thread t(std::ref(... 阅读全文
posted @ 2012-11-29 16:07 juice_li 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 源代码: 1 #include <iostream> 2 #include <thread> 3 #include <string> 4 #include <chrono> 5 6 void th1() 7 { 8 for(int i=0; i<5; i++){ 9 std::cout<<"th1--"<<i<<std::endl;10 std::this_thread::sleep_for(std::chrono::seconds(1));//@111 }12 }13 void th 阅读全文
posted @ 2012-11-29 15:46 juice_li 阅读(2090) 评论(0) 推荐(0) 编辑
摘要: 源代码(引用文档中例子): 1 #include <iostream> 2 #include <chrono> 3 #include <thread> 4 #include <mutex> 5 #include <map> 6 #include <string> 7 8 std::map<std::string, std::string> g_pages; 9 std::mutex g_pages_mutex;10 11 void save_page(const std::string &url)12 阅读全文
posted @ 2012-11-29 09:53 juice_li 阅读(2951) 评论(0) 推荐(0) 编辑