#include "sylar/sylar.h"#include <unistd.h>sylar::Logger::ptr g_logger = SYLAR_LOG_ROOT();int count = 0;//sylar::RWMutex s_mutex;sylar::Mutex s_mutex;void fun1() {SYLAR_LOG_INFO(g_logger) << "name: " << sylar::Thread::GetName()<< " this.name: " << sylar::Thread::GetThis()->getName()<< " id: " << sylar::GetThreadId()<< " this.id: " << sylar::Thread::GetThis()->getId();for(int i = 0; i < 100000; ++i) {//sylar::RWMutex::WriteLock lock(s_mutex);sylar::Mutex::Lock lock(s_mutex);++count;}}void fun2() {while(true) {SYLAR_LOG_INFO(g_logger) << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";}}void fun3() {while(true) {SYLAR_LOG_INFO(g_logger) << "========================================";}}int main(int argc, char** argv) {SYLAR_LOG_INFO(g_logger) << "thread test begin";YAML::Node root = YAML::LoadFile("/home/sylar/test/sylar/bin/conf/log2.yml");sylar::Config::LoadFromYaml(root);std::vector<sylar::Thread::ptr> thrs;for(int i = 0; i < 1; ++i) {sylar::Thread::ptr thr(new sylar::Thread(&fun2, "name_" + std::to_string(i * 2)));//sylar::Thread::ptr thr2(new sylar::Thread(&fun3, "name_" + std::to_string(i * 2 + 1)));thrs.push_back(thr);//thrs.push_back(thr2);}for(size_t i = 0; i < thrs.size(); ++i) {thrs[i]->join();}SYLAR_LOG_INFO(g_logger) << "thread test end";SYLAR_LOG_INFO(g_logger) << "count=" << count;return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。