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
Session communication without Mutex? #2858
Comments
The point of the mutex is that foreign threads can concurrently call a "send" function to add the string to a queue. If you want that feature then you have to have the mutex. Alternatively you can call If you are worried about performance, don't be. There is little to no contention for the lock, as the mutex is held for the shortest possible time, and you don't have such a large number of threads trying to queue a string at the same time that the performance would matter. |
Very helpful, thank you, @vinniefalco. |
Quick follow-up question, @vinniefalco: Is |
I like the vector because it is very clear and understandable. I don't know what's going on with this other buffer. Who changed it? Maybe the buffer is more efficient. But the vector is more readable, as evidenced by your question. |
1.84
Looking for advice on migrating the session communication
Older version
Concerning session communication (with client), I had developed an app using beast example a few years ago.
Wherein i used "mutex" for guarding the write as well as "vector" for queuing the messages, etc. Here is a snippet of how it is:
And my write function is like this:
In the latest example,
When I recently studying the latest examples, I found that this part of the code has been migrated, made bit simpler and perhaps sounds more efficient too—without mutex and vector. All managed through "buffer". I am looking for your guidance on whether I can migrate to this one without any drawbacks.
// we use the buffer beast::flat_buffer buffer_;
And we use this write function
Thanks in advance!
Regards,
Tharma
The text was updated successfully, but these errors were encountered: