Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
718 views
in Technique[技术] by (71.8m points)

multithreading - C++ thread safe string wrapper

Hello i am writing thread safe wrapper for std::string

class ThreadSafeString
{
public:
    ThreadSafeString(std::string&& str) noexcept
    {
        std::scoped_lock lock(mutexString);
        buffer = std::move(str);
    }

private:
    std::string buffer;
    std::mutex mutexString;
};

constructor is marked with warning:

warning C26111: Caller failing to release lock <lock> before calling function <func>.
  1. what is caller and what is calling function? i dont call any function with same mutex in ctor.
  2. is my wrapper thread safe? what is better way do thread safe string if i need copy/move ctor/operator=()
question from:https://stackoverflow.com/questions/65859214/c-thread-safe-string-wrapper

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...