We are porting an app from 10.6 to 10.8. I am looking at dylib we load in app. I am facing very unusual crash in Garbage Collection Work Queue with following message.
malloc: Thread::suspend(): unable to suspend a thread: err = 268435459, Thread 0x111000000: _pthread = 0x108129000, _thread = 0x8b07, _stack_base = 0x108129000, enlivening on, 0 local blocks
For application GCC_ENABLE_OBJC_GC = required
is set. If I have GCC_ENABLE_OBJC_GC = required
in dylib it will still crash. I cannot turn off garbage collector in application. I have to manage it crash from my dylib.
Reason for crash turns out to be that garbage collector is not able to suspend the thread. (as it says in log). This thread is created using thread_create(). If I put a indefinite while loop (with sleep) in constructor of dylib, I dont get crash. I get crash when constructor has finished its execution.
Is their a way to tell garbage collector not to try and suspend the thread? Or to increase reference count of thread? or anything I can do to stop garbage collector not to interfere with my dylib code.
From Apple documentation about 10.8:
Important: Beginning in OS X v10.8, garbage collection is deprecated. Use ARC (Automatic Reference Counting) instead. To learn more about ARC, see Transitioning to ARC Release Notes.
https://books.google.co.in/books?id=8nzwsciij20C&pg=PT431&lpg=PT431&dq=Crash+of+Garbage+Collection+Work+in+objective+c&source=bl&ots=xTjLETFMsO&sig=b33rLeXJVh1WtnAvcVJykfNtvOU&hl=en&sa=X&ved=0ahUKEwiyqZrC2rvNAhVKNI8KHZRdC7AQ6AEIKDAC#v=onepage&q=Crash%20of%20Garbage%20Collection%20Work%20in%20objective%20c&f=false
It is expected.
Starting with OSX 10.8, Garbage collection is deprecated. So CG is unable to suspend the threads to perform its duty. As a result you get all the issues you are facing.
If you want to develop for 10.8, you need to convert to ARC (best) or move back to manual reference counting. If you wish to move to arc, see Transitioning to ARC Release Notes
From Apple documentation about 10.8:
Source: What's new in OS X v10.8 Mountain Lion:
Answers:
No. That's how it works.
No. Since GC is deprecated under 10.8, sou have to get rid of it if you wish to support 10.8.
GC has been a really short-lived technology on the MAC platform. And replaced by ARC for various reasons.