How to stop std thread safely?

I’m developing a chat server and I have a question.

How to stop std::thread safely?

it is very easy problem, like this.

thread t(&func);
t.join();
but, if func is has infinite loop, join is …

Lock dictionary within same thread

I have a function that returns an entry on a dictionary, based on the Key (name) and if it doesn’t exist, returns a newly created one.

The question I have is with the “double lock” : SomeFunction …