Yes you can do it, it will be safe
... until the second programmer appears and understands the same assumptions that you made. This second (or 3rd, 4th, 5th, ...) programmer is likely to start using the object in an unsafe way (in the thread of the creator). Caused problems can be very subtle and difficult to track. For this reason alone and because it is so tempting to use this object in multiple threads, I would make the object a thread safe.
To clarify (thanks to those who left comments):
By "thread safe" I mean programmatically designing a circuit to avoid threading issues. I do not necessarily want to develop a locking scheme around your object. You could find a way in your language to make it illegal (or very difficult) to use the object in the creator thread. For example, restricting the scope in the creator stream to a block of code that creates an object. After creating, pass the object to the user stream, making sure that the creator stream no longer refers to it.
For example, in C ++
void CreateObject() { Object* sharedObj = new Object(); PassObjectToUsingThread( sharedObj);
Then, in your creation stream, you no longer have access to the object after its creation, responsibility is transferred to the used stream.
Doug T.
source share