Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
qt 使用acl 全局指针获取线程池内的连接 获取不到。崩溃 #202
Comments
|
你调用 peek 时不会是 redis_pool() 函数已经返回了吧 |
根据demo修改,增加一个类。redis_con 全家变量 g_redis_c
class redis_con()
{
acl::redis_client_pool& pool_
redis_con::redis_con(acl::redis_client_pool& pool):pool_(pool)
{
}
acl::redis_client* redis_con::get_conn()
{
acl::redis_client* conn= nullptr;
conn = (acl::redis_client*) pool_.peek();//全局使用崩溃。
if (conn == nullptr)
{
printf("peek redis connection error\r\n");
return conn= nullptr;
}
else
{
return conn;
}
}
}
test()
{
acl::redis_client* conn = g_redis_c->get_conn();
/////这句出现崩溃
}
void redis_pool(const char* redis_addr, int max_threads,int conn_timeout, int rw_timeout)
{
acl::redis_client_pool pool(redis_addr, max_threads);
pool.set_timeout(conn_timeout, rw_timeout);
g_redis_c = new redis_con(pool);
//如果在这个函数里面使用g_redis_c.get_conn()就正常。
}
main
{
redis_poo(,,,)
test()
}
请求帮忙解答一下。谢谢!