Re: RunLoop in Helper Tool
On 16 Sep 2013, at 01:10, Greg Parker gpar...@apple.com wrote: And of course every Cocoa app halts by calling exit(). NSApplicationMain() never returns. (I'm pretty sure it doesn't attempt to stop the main run loop, either.) It does go and close all documents and send NSApplicationWillTerminateNotification and ask the app delegate if it’s OK to quit though. So it’s a tad more graceful than just exit() alone. But yeah, NSApplicationMain doesn’t return, and that silly autorelease pool most people put in main() these days never gets released, just accumulating any objects that get autoreleased on the main thread without any other pool in place. All things to keep in mind. Cheers, -- Uli Kusterer “The Witnesses of TeachText are everywhere...” http://zathras.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
On Sep 16, 2013, at 9:12 , Uli Kusterer witness.of.teacht...@gmx.net wrote: On 16 Sep 2013, at 01:10, Greg Parker gpar...@apple.com wrote: And of course every Cocoa app halts by calling exit(). NSApplicationMain() never returns. (I'm pretty sure it doesn't attempt to stop the main run loop, either.) It does go and close all documents and send NSApplicationWillTerminateNotification and ask the app delegate if it’s OK to quit though. So it’s a tad more graceful than just exit() alone. Hmm…I don’t think Greg or anyone else said anything about calling exit() alone. For example: On Sep 15, 2013, at 16:30 , Marcel Weiher marcel.wei...@gmail.com wrote: Do all the cleanup you want to do and then exit(0) ? But yeah, NSApplicationMain doesn’t return, and that silly autorelease pool most people put in main() these days never gets released, just accumulating any objects that get autoreleased on the main thread without any other pool in place. Yes, hopefully it doesn’t get released. The reason to put it there was to avoid console messages of the form “object xyz autoreleased without a pool in place - just leaking”. Better to have them leak silently in a pool than with a console message, if they are indeed top-level objects that are supposed to stick around. Just testing it now on my Mac doesn’t show the message. Has it been removed/optionalized or are we now getting an automatic top-level pool? Marcel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
RunLoop in Helper Tool
I have a Helper Tool, running as root, started via SMJobBless and communicating vie Xpc. Works fine, but: 1. it cannot stop (CFRunLoopStop), 2. Timers never fire 3. NSRunLoop currentMode returns nil. Maybe all three things are related. To 1: if ( asked to quit ) { NSRunLoop *currentRunLoop = [ NSRunLoop currentRunLoop ]; CFRunLoopRef rl = [ currentRunLoop getCFRunLoop ]; NSLog(@%s will stop runloop %p,__FUNCTION__, rl); // rl ≠ NULL CFRunLoopStop ( rl ); // runLoop will NOT stop } Helper Tool main: int main(int argc, const char * argv[]) { @autoreleasepool { NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName: bundleIdentifier ]; listener.delegate = ...; [listener resume]; NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop]; [ currentRunLoop run ]; } return EXIT_SUCCESS; } ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
XPC is based on GCD. There is chance that your request handling occurs in a GCD thread and not on the main thread. [NSRunLoop currentRunLoop] returns the current thread run loop. If you are not on the main thread, it will not work. Try that instead: CFRunLoopStop(CFRunLoopGetMain()); Le 15 sept. 2013 à 10:32, Gerriet M. Denkmann gerr...@mdenkmann.de a écrit : I have a Helper Tool, running as root, started via SMJobBless and communicating vie Xpc. Works fine, but: 1. it cannot stop (CFRunLoopStop), 2. Timers never fire 3. NSRunLoop currentMode returns nil. Maybe all three things are related. To 1: if ( asked to quit ) { NSRunLoop *currentRunLoop = [ NSRunLoop currentRunLoop ]; CFRunLoopRef rl = [ currentRunLoop getCFRunLoop ]; NSLog(@%s will stop runloop %p,__FUNCTION__, rl); // rl ≠ NULL CFRunLoopStop ( rl ); // runLoop will NOT stop } Helper Tool main: int main(int argc, const char * argv[]) { @autoreleasepool { NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName: bundleIdentifier ]; listener.delegate = ...; [listener resume]; NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop]; [ currentRunLoop run ]; } return EXIT_SUCCESS; } ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/devlists%40shadowlab.org This email sent to devli...@shadowlab.org -- Jean-Daniel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
On 15 Sep 2013, at 16:42, Jean-Daniel Dupas devli...@shadowlab.org wrote: XPC is based on GCD. There is chance that your request handling occurs in a GCD thread and not on the main thread. Correct. NSThread tells me: mainThread NSThread: 0x7f92b14096a0{name = (null), num = 1} currentThread NSThread: 0x7f92b3502cf0{name = (null), num = 2} [NSRunLoop currentRunLoop] returns the current thread run loop. If you are not on the main thread, it will not work. NSRunLoop *currentRunLoop = [ NSRunLoop currentRunLoop ]; CFRunLoopRef rl1 = [ currentRunLoop getCFRunLoop ]; // mode = nil CFRunLoopRef rl2 = CFRunLoopGetMain (); // mode = kCFRunLoopDefaultMode Try that instead: CFRunLoopStop(CFRunLoopGetMain()); Tried it. Even tried stopping both run loops, but to no avail. The helper tool just will not quit. But maybe I will be able to make my NSTimers work now having a better understanding of what is going on. Thanks! Gerriet. Le 15 sept. 2013 à 10:32, Gerriet M. Denkmann gerr...@mdenkmann.de a écrit : I have a Helper Tool, running as root, started via SMJobBless and communicating vie Xpc. Works fine, but: 1. it cannot stop (CFRunLoopStop), 2. Timers never fire 3. NSRunLoop currentMode returns nil. Maybe all three things are related. To 1: if ( asked to quit ) { NSRunLoop *currentRunLoop = [ NSRunLoop currentRunLoop ]; CFRunLoopRef rl = [ currentRunLoop getCFRunLoop ]; NSLog(@%s will stop runloop %p,__FUNCTION__, rl); // rl ≠ NULL CFRunLoopStop ( rl ); // runLoop will NOT stop } Helper Tool main: int main(int argc, const char * argv[]) { @autoreleasepool { NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName: bundleIdentifier ]; listener.delegate = ...; [listener resume]; NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop]; [ currentRunLoop run ]; } return EXIT_SUCCESS; } ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
On Sep 15, 2013, at 10:32 , Gerriet M. Denkmann gerr...@mdenkmann.de wrote: I have a Helper Tool, running as root, started via SMJobBless and communicating vie Xpc. Works fine, but: 1. it cannot stop (CFRunLoopStop), Do all the cleanup you want to do and then exit(0) ? Marcel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
Interesting that you should say that. I was doing exit(0) but after reading this discussion I thought it would be cleaner to do the CFRunLoopStop on the main thread. Unfortunately I'd broken my LaunchAgent doing some other stuff at the time and just now I've got stuff working and then I've been wondering why LaunchAgent doesn't stop. Back to exit(0) it is. Kevin On 15 Sep 2013, at 15:30, Marcel Weiher marcel.wei...@gmail.com wrote: On Sep 15, 2013, at 10:32 , Gerriet M. Denkmann gerr...@mdenkmann.de wrote: I have a Helper Tool, running as root, started via SMJobBless and communicating vie Xpc. Works fine, but: 1. it cannot stop (CFRunLoopStop), Do all the cleanup you want to do and then exit(0) ? Marcel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/ktam%40yvs.eu.com This email sent to k...@yvs.eu.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
Le 15 sept. 2013 à 16:23, Gerriet M. Denkmann gerr...@mdenkmann.de a écrit : On 15 Sep 2013, at 16:42, Jean-Daniel Dupas devli...@shadowlab.org wrote: XPC is based on GCD. There is chance that your request handling occurs in a GCD thread and not on the main thread. Correct. NSThread tells me: mainThreadNSThread: 0x7f92b14096a0{name = (null), num = 1} currentThread NSThread: 0x7f92b3502cf0{name = (null), num = 2} [NSRunLoop currentRunLoop] returns the current thread run loop. If you are not on the main thread, it will not work. NSRunLoop *currentRunLoop = [ NSRunLoop currentRunLoop ]; CFRunLoopRef rl1 = [ currentRunLoop getCFRunLoop ]; // mode = nil CFRunLoopRef rl2 = CFRunLoopGetMain (); // mode = kCFRunLoopDefaultMode Try that instead: CFRunLoopStop(CFRunLoopGetMain()); Tried it. Even tried stopping both run loops, but to no avail. The helper tool just will not quit. But maybe I will be able to make my NSTimers work now having a better understanding of what is going on. Now that you mention it, I remember it is not possible to stop a [NSRunLoop run] call (at least not in a reliable way). See the -[NSRunLoop run] documentation for an alternative way to do that, or just call exit() as others have suggested. -- Jean-Daniel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
On Sep 15, 2013, at 17:04 , Kevin Meaney k...@yvs.eu.com wrote: On 15 Sep 2013, at 15:30, Marcel Weiher marcel.wei...@gmail.com wrote: Do all the cleanup you want to do and then exit(0) ? I was doing exit(0) but after reading this discussion I thought it would be cleaner to do the CFRunLoopStop on the main thread. I also used to think it was a good idea to clean up after yourself. However, a lot of in-process cleanup is at best just simply wasted, the OS will recover all those resources much more effectively and safely. What’s worse, the cleanup code can cause significant issues, I remember the image processing program that swapped back a lot of its image-cache in the process of freeing it, because the malloc metadata was kept on the same VM page as the data itself. Unfortunately I'd broken my LaunchAgent doing some other stuff at the time and just now I've got stuff working and then I've been wondering why LaunchAgent doesn't stop. Back to exit(0) it is. If you get queasy about exiting so abruptly, remind yourself that sudden termination is a kill -9 … :-) Marcel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: RunLoop in Helper Tool
On Sep 15, 2013, at 10:50 AM, Marcel Weiher marcel.wei...@gmail.com wrote: On Sep 15, 2013, at 17:04 , Kevin Meaney k...@yvs.eu.com wrote: On 15 Sep 2013, at 15:30, Marcel Weiher marcel.wei...@gmail.com wrote: Do all the cleanup you want to do and then exit(0) ? I was doing exit(0) but after reading this discussion I thought it would be cleaner to do the CFRunLoopStop on the main thread. Back to exit(0) it is. If you get queasy about exiting so abruptly, remind yourself that sudden termination is a kill -9 … :-) And of course every Cocoa app halts by calling exit(). NSApplicationMain() never returns. (I'm pretty sure it doesn't attempt to stop the main run loop, either.) -- Greg Parker gpar...@apple.com Runtime Wrangler ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com