Your implementation is thread safe because you have protected with mutex your access to attribute.
Here, your class is a thread, so your object is a thread. It's what you do in your thread that tell if it is thread safe.
You get your value with a lock/unlock system and you write it with the same system. So your function is thread safe.