C++ Multithreaded server help

柔情痞子 提交于 2019-12-04 13:14:32

Whatever class maintains this vector of connections needs a strand. Use strand::post or strand::dispatch when accessing, adding to, or removing from the vector. The strand concept is explained in detail in the documentation.

A strand is defined as a strictly sequential invocation of event handlers (i.e. no concurrent invocation). Use of strands allows execution of code in a multithreaded program without the need for explicit locking (e.g. using mutexes).

Is putting a lock around the vector not an option? Have every access to the vector first acquire a lock; that will prevent your race condition. As long as server connections don't come and go very frequently, it won't be a bottleneck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!