moveToThread not thread-safe
Hi all,
I'm working in a library where objects are created and moved to a specific thread (global reference). The library must support multi threading this means that different objects can be created simultaneously and moved to this global thread instance.
Do I need to have a lock to protect my global thread when moving those objects?
I understand that moveToThread is not thread-safe if trying to move the same object but how about the thread instance.
Thanks
Montez
Re: moveToThread not thread-safe
Documentation:
Quote:
Warning: This function is not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only "push" an object from the current thread to another thread, it cannot "pull" an object from any arbitrary thread to the current thread.
So as long as the thread calling x.moveToThread(global_thread) is the same thread that created (or rather, currently owns) the object you are fine.
Re: moveToThread not thread-safe
This is great!
Thx a lot for your reply.
Montez