News for hackers. Stuff that matters.
Re:MutexProtected: A C++ Pattern for Easier Concurrency by kajaktum on Thursday April 06, 2023 @01:15PM (#35471425)
You specifically mentioned that this is a footgun:

> auto& x = state.locked()->x;

But I don't see how the reference here is gonna make a difference unless i am reading the lifetime of the lock here incorrectly. For example, this is perfectly fine right?

```

{

auto& x = state.locked()->x;

}

```

This will only be a problem if you have an outside struct that holds a reference

```

auto &a = "something";

{

auto& x = state.locked()->x;

a = x;

}

```

Which can still happen even if you use a lambda.

There are no comments on this comment yet.