PDA

View Full Version : moveToThread not thread-safe



mont3z
22nd March 2019, 15:38
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

tuli
22nd March 2019, 16:58
Documentation:
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.

mont3z
22nd March 2019, 21:27
This is great!
Thx a lot for your reply.
Montez