Crash of Garbage Collection Work Queue if dylib is loaded

时光怂恿深爱的人放手 提交于 2019-12-06 19:01:28

问题


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.


回答1:


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:

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




回答2:


We are porting an app from 10.6 to 10.8. Reason for crash turns out to be that garbage collector is not able to suspend the thread.

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:

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.

Source: What's new in OS X v10.8 Mountain Lion:

Answers:

  • Is their a way to tell garbage collector not to try and suspend the thread?

No. That's how it works.

  • Or to increase reference count of thread? Or anything I can do to stop garbage collector not to interfere with my dylib code.

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.



来源:https://stackoverflow.com/questions/14817070/crash-of-garbage-collection-work-queue-if-dylib-is-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!