Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt 使用acl 全局指针获取线程池内的连接 获取不到。崩溃 #202

Open
jiasondouble opened this issue Apr 16, 2020 · 1 comment

Comments

@jiasondouble
Copy link

@jiasondouble jiasondouble commented Apr 16, 2020

根据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()
}
请求帮忙解答一下。谢谢!

@zhengshuxin
Copy link
Member

@zhengshuxin zhengshuxin commented Apr 19, 2020

你调用 peek 时不会是 redis_pool() 函数已经返回了吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.