discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

libdispatch problem


From: allynm
Subject: libdispatch problem
Date: Wed, 24 Jun 2015 13:08:44 -0700 (MST)

Hello everyone,

This is probably more a libobjc2 type question.  Hopefully, not.

I have the following program, based off an original work by Tobias Lensing.


> #import 
> <
> Foundation/Foundation.h
> >
> #import 
> <
> AppKit/AppKit.h
> >
> #import 
> <
> dispatch/dispatch.h
> >
> int main (int argc, const char * argv[])
> {
> @autoreleasepool{
>   int multiplier = 7;
>   int (^myBlock)(int) = ^(int num){
>     return num *multiplier;
>    };
> 
> NSLog(@"%d", myBlock(3));
> 
>  dispatch_queue_t queue = dispatch_queue_create("Example.one",NULL);
> 
>   dispatch_sync(queue, ^{printf("Hello, world from a dispatch queue!\n");
>    });
> NSLog(@"got past the dispatch queue, on to the pic ...");
> //}
> 
> //@autoreleasepool{
>   [NSApplication sharedApplication];
>   //cd ~/
> NSAlert * alert = [[NSAlert alloc] init];  //alerWithE(@"TEST", @"Wow it
> works!", @"OK", nil, nil);
> [alert addButtonWithTitle:@"OK"];
> [alert addButtonWithTitle:@"Cancel"];
> [alert setMessageText:@"Delete the record?"];
> [alert setInformativeText:@"Deleted records cannot be restored!"];
> 
> [alert setAlertStyle:NSWarningAlertStyle];
> if ([alert runModal] == NSAlertFirstButtonReturn){
> return 0;
>  }
> 
> }
> 
>   return 0;
> }

If I remove the comments around the "}"  and the following
"@autoreleasepool" directive the program crashes with a seg fault before it
runs the little NSAlert window enclosed by the second @autoreleasepool.  If
there is only a single @autoreleasepool directive and closing "}" the
program runs just fine.  I'm a novice on this stuff.  Could someone with a
better knowledge of GCD and ARC explain what's happening?

Thanks,
Mark Allyn




--
View this message in context: 
http://gnustep.8.n7.nabble.com/libdispatch-problem-tp39436.html
Sent from the GNUstep - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]