如何启动一个运行类函数的boost线程?(How can I start a boost Thread running a class function?)
我正在做一个C ++类,在内部,我想创建一个线程来执行类的功能,我该怎么做? 我给你看一些代码。
我希望在一个线程中运行的成员函数:
void SocketServer::runServer(){ bool connected; tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), puerto)); std::string data; while(seguirFuncionando()){ miSocket = new tcp::socket(io_service); std::cout << "Waiting for connection...\n"; a.accept(*miSocket); std::cout << "Connected\n"; connected = true; try{ while (connected){ data = readStr(); if (data.compare("")==0){ std::cout << "End of connection.\n"; } else{ std::cout << data << "\n"; } } } catch (std::exception& e){ std::cerr << "Exception in thread: " << e.what() << "\n"; } } }
我想做什么:
void SocketServer::runThreadServer(){ asio::thread t(runServer); }
但它没有编译。 错误:
没有匹配函数来调用'asio :: thread :: thread()注意:候选者是:asio :: thread :: thread(Function)[with Function = void(SocketServer :: *)()]
我该怎么做?
感谢名单。
im doing a C++ class where, internally, i want to create a thread to execute a function of the class, how can I do this? I show you some code.
Member function i want to run in a thread:
void SocketServer::runServer(){ bool connected; tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), puerto)); std::string data; while(seguirFuncionando()){ miSocket = new tcp::socket(io_service); std::cout << "Waiting for connection...\n"; a.accept(*miSocket); std::cout << "Connected\n"; connected = true; try{ while (connected){ data = readStr(); if (data.compare("")==0){ std::cout << "End of connection.\n"; } else{ std::cout << data << "\n"; } } } catch (std::exception& e){ std::cerr << "Exception in thread: " << e.what() << "\n"; } } }
What im trying to do:
void SocketServer::runThreadServer(){ asio::thread t(runServer); }
But it doesnt compile. Error:
no matching function for call to 'asio::thread::thread() note: candidates are: asio::thread::thread(Function) [with Function = void (SocketServer::*)()]
How should i do this?
Thanx.
原文:https://stackoverflow.com/questions/9232010
最满意答案
您可以使用“遗留索引”来索引关系属性,这不再是完全推荐的,但是这不会指示缺少关系,因此它对您没有任何好处。 我可能会尝试找到一种方法,通过标签或属性索引来标记需要关系的节点。 从那里开始你的比赛,它会更快。
You can index relationship properties using "legacy indexing," which isn't exactly recommended anymore, but this won't index the absence of relationships so it wouldn't do you any good. I'd probably try to find a way to mark nodes in need of relationships through either a label or an index on a property. Start your match from there, it'll be much faster.
相关问答
更多-
主键是一个逻辑概念 - 它是表中一行的唯一标识符。 因此,它有一堆属性 - 它可能不为null,它必须是唯一的。 当然,由于您很可能通过其唯一标识符搜索记录,所以在主键上设置一个索引是很好的。 聚集索引是物理概念 - 它是影响磁盘上记录的顺序的索引。 这使得访问数据时的速度非常快,尽管如果主键不是序列号,它可能会减慢写入速度。 是的,您可以使用没有聚簇索引的主键 - 有时您可能需要(例如,当您的主键是加入表中的外键的组合,并且您不想导致磁盘随机播放的开销写作时)。 是的,您可以在不是主键的列上创建聚簇索引。 ...
-
这是(动态)生成的用于键值编码合规性的访问器方法,请参阅“键值编码编程指南”中的键值编码访问器方法 : 为了使密钥值编码符合可变的有序到多个关系,您必须实现以下方法: ... -objectIn
AtIndex:或- AtIndexes: . 必须实施其中一种方法。 它们对应于NSArray methods objectAtIndex:和objectsAtIndexes: ... 为了支持对无序多对多关系的只读访问,您将实现以下方法: ... -memberOf : . 需要。 此方 ... -
可以使用关系属性进行查询。 您可以采用与节点相同的方式执行此操作: match (n)-[r:SOME_RELATIONSHIP]-() where r.someProperty = someValue return distinct n 要么 match (n)-[:SOME_RELATIONSHIP { someProperty: someValue }]-() return distinct n It is possible to make queries using relationship p ...
-
当您键入:schema ,您看到的索引是Neo4j中的新式索引。 似乎node_auto_indexing和relationship_auto_indexing (以及*_keys_indexable )配置属性是Neo4j遗留索引的一部分: http://neo4j.com/docs/milestone/auto-indexing.html 我不太熟悉遗留索引,但在新式索引中没有关系的索引。 在该范例中,您首先通过索引找到节点并遵循那里的关系,但是没有首先找到节点就没有直接查询关系。 您可以在此处阅读有关 ...
-
查询关系存在,如何根据数组长度添加条件(Querying Relationship Existence, how to add conditions depending on an array length)[2022-03-08]
用这个: $query = Pub::query(); foreach ($tapps_chosen as $tappId) { $query->whereHas('pubTapps', function($query) use($tappId) { $query->where('tapp_id', $tappId); }); } return $query->get(); Use this: $query = Pub::query(); foreach ($tapps_c ... -
为什么不把你的支票放在一个begin...rescue...end块? Why not just put your checks in a begin...rescue...end block?
-
您可以使用“遗留索引”来索引关系属性,这不再是完全推荐的,但是这不会指示缺少关系,因此它对您没有任何好处。 我可能会尝试找到一种方法,通过标签或属性索引来标记需要关系的节点。 从那里开始你的比赛,它会更快。 You can index relationship properties using "legacy indexing," which isn't exactly recommended anymore, but this won't index the absence of relationship ...
-
我觉得在某一点之后你也可以尝试一下 try { x = my_var[2].attr[4][2] } catch (e) { // handle and continue } I feel like after a certain point you might as well just try-catch try { x = my_var[2].attr[4][2] } catch (e) { // handle and continue }
-
你试过COUNT吗? SELECT COUNT(*) FROM issues WHERE time.id = issues.parent_id AND parent_type = \'' . TimeRecord::class . '\' AND deleted_at IS NULL Have you tried COUNT? SELECT COUNT(*) FROM issues WHERE time.id = issues.parent_id AND parent_type ...
-
KeystoneJS尝试将createItem()与relationShip字段一起使用(KeystoneJS trying to use createItem() with relationShip field)[2023-04-06]
我最终找到了解决方案,所以我给你了。 不幸的是,我没有设法使用Keystone Framework中的现有updateHandler。 相反,在这里我做了什么: 我使用查询从名称中查找对象的id: var yourTableQuery = query.select('id').exec(function(err, yourTableId) 然后我用mogoose方式创建了一个对象: item = new yourTable.model({ relationship: yourTableId }) 并且链 ...