Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ACAccount thread safe?

Can I share a single ACAccount instance between threads? Specifically I would like to create multiple TWRequest objects that are used by different NSOperationQueue instances. Those TWRequest objects will share a single ACAccount instance. Is that safe?

Thanks.

like image 804
adib Avatar asked Dec 01 '11 23:12

adib


1 Answers

I'm going to say, "no." Firstly, ACAccount does not appear on Apple's "Thread Safe" list. Secondly, I see no explicit mention of thread safety in the reference for either of those classes. Thirdly, I see that TWRequest appears to be built upon NSURLConnection which is designed for use on a run loop (typically the main thread). I see nothing at all to indicate that these classes are safe for concurrent use from multiple threads. At best, you should take a thread-confinement approach (i.e. each thread fetches/creates its own copies of these objects and should not pass them between threads.)

Since TWRequest is designed for cooperative/runloop-based operation, I see no reason that you would need to do this stuff on a background thread either, FWIW.

So yeah. I'd say, "no."

like image 91
ipmcc Avatar answered Oct 06 '22 21:10

ipmcc