Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NSThreading

29 views
Skip to first unread message

Andor Kocsis

unread,
Nov 13, 2012, 4:46:44 PM11/13/12
to discuss...@gnu.org
Could someone help me plz with this simple program?

--------------------------------------------------------------
#import <Foundation/Foundation.h>

@interface obj1: NSObject { }
-(void) do_it:(id)p1;
@end

@implementation obj1
-(void) do_it:(id)p1 {
  NSAutoreleasePool* pool= [[NSAutoreleasePool alloc] init];
  NSLog(@"obj1#tick");
  [pool drain];}
@end

int main (int argc, const char * argv[]) {
  NSAutoreleasePool* pool= [[NSAutoreleasePool alloc] init];
  obj1* obj= [[obj1 alloc] init];
  [NSThread detachNewThreadSelector:
      NSSelectorFromString(@"do_it")
      toTarget:obj withObject:obj];
  NSLog(@"main#tick");
  [NSThread sleepForTimeInterval:0.5];
  [pool drain];
  return 0;}

-------------------------------------------------------------------------

Program's output:
-------------------------------------------------------------------------
2012-11-13 22:39:20.820 helloworld[2900] autorelease called without pool for obj
ect (0x749c58) of class GSCInlineString in thread <NSThread: 0x749b68>
2012-11-13 22:39:20.789 helloworld[2900] WARNING - unable to create shared user
defaults!
2012-11-13 22:39:20.836 helloworld[2900] main#tick
2012-11-13 22:39:20.836 helloworld[2900] autorelease called without pool for obj
ect (0x749400) of class NSException in thread <NSThread: 0x749b68>
2012-11-13 22:39:20.851 helloworld[2900] autorelease called without pool for obj
ect (0x36bc358) of class GSMutableArray in thread <NSThread: 0x749b68>
helloworld.exe: Uncaught exception NSInvalidArgumentException, reason: -[obj1 do
_it]: unrecognized selector sent to instance 0x748690

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

-------------------------------------------------------------------------


Using latest SDK on Windows. There isn't any compile time error or warning. How to fix this simple NSThread example to run properly?

Thx,

Jamison Hope

unread,
Nov 13, 2012, 5:08:05 PM11/13/12
to Andor Kocsis, discuss...@gnu.org
That should be 'NSSelectorFromString(@"do_it:")' with the colon at the end.
At least, that fixes it compiling/running on Cocoa, so I assume it's the
same issue for GNUstep.. and it is, look at your error message:
> reason: -[obj1 do_it]: unrecognized selector

Jamie
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss...@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Tom Davie

unread,
Nov 13, 2012, 5:24:57 PM11/13/12
to Jamison Hope, discuss...@gnu.org

On 13 Nov 2012, at 22:08, Jamison Hope <j...@theptrgroup.com> wrote:

> That should be 'NSSelectorFromString(@"do_it:")' with the colon at the end.
> At least, that fixes it compiling/running on Cocoa, so I assume it's the
> same issue for GNUstep.. and it is, look at your error message:

Or, alternatively, @selector(do_it:), which will allow the compiler to verify that the selector actually exists somewhere.

Bob


Andor Kocsis

unread,
Nov 14, 2012, 4:11:43 AM11/14/12
to discuss...@gnu.org
Thanks to everyone for fast and accurate help. Selector fixed to "do_it:", and it works now. However still have a warning, and have no idea, how to avoid it. Programs output now:

------------------------------------------------
2012-11-14 09:13:32.020 helloworld[3096] obj1#tick
2012-11-14 09:13:31.980 helloworld[3096] WARNING - unable to create shared user
defaults!
2012-11-14 09:13:32.030 helloworld[3096] main#tick
------------------------------------------------

It complains only when NSThread starts - no warning about user defaults without NSThread. I am with admin rights on my Windows 7 system, and should not be a problem to create a file, if something library function really want to do that in depths. Also searched for a user defaults file, what it should to be on Windows system, thought no problem with creation, if system already have it. Not so much found.

Can i download one somewhere? Or any other way to fix it?


From: Tom Davie <tom....@gmail.com>
To: Jamison Hope <j...@theptrgroup.com>
Cc: Andor Kocsis <andor_...@yahoo.com>; discuss...@gnu.org
Sent: Tuesday, November 13, 2012 11:24 PM
Subject: Re: NSThreading

Luboš Doležel

unread,
Nov 14, 2012, 4:56:09 AM11/14/12
to Andor Kocsis, discuss...@gnu.org
On Windows 7, the application IMO needs to actually request admin
privileges in order to have them.

Try running the app under admin privileges (right click - Run as
administrator) and it should be OK.

Lubos

On 14.11.2012 10:11, Andor Kocsis wrote:
> Thanks to everyone for fast and accurate help. Selector fixed to
> "do_it:", and it works now. However still have a warning, and have no
> idea, how to avoid it. Programs output now:
>
> ------------------------------------------------
> 2012-11-14 09:13:32.020 helloworld[3096] obj1#tick
> 2012-11-14 09:13:31.980 helloworld[3096] WARNING - unable to create
> shared user
> defaults!
> 2012-11-14 09:13:32.030 helloworld[3096] main#tick
> ------------------------------------------------
>
> It complains only when NSThread starts - no warning about user defaults
> without NSThread. I am with admin rights on my Windows 7 system, and
> should not be a problem to create a file, if something library function
> really want to do that in depths. Also searched for a user defaults
> file, what it should to be on Windows system, thought no problem with
> creation, if system already have it. Not so much found.
>
> Can i download one somewhere? Or any other way to fix it?
>
> ------------------------------------------------------------------------
> *From:* Tom Davie <tom....@gmail.com>
> *To:* Jamison Hope <j...@theptrgroup.com>
> *Cc:* Andor Kocsis <andor_...@yahoo.com>; discuss...@gnu.org
> *Sent:* Tuesday, November 13, 2012 11:24 PM
> *Subject:* Re: NSThreading
>
>
> On 13 Nov 2012, at 22:08, Jamison Hope <j...@theptrgroup.com
> <mailto:j...@theptrgroup.com>> wrote:
>
> > That should be 'NSSelectorFromString(@"do_it:")' with the colon at
> the end.
> > At least, that fixes it compiling/running on Cocoa, so I assume it's the
> > same issue for GNUstep.. and it is, look at your error message:
>
> Or, alternatively, @selector(do_it:), which will allow the compiler to
> verify that the selector actually exists somewhere.
>
> Bob
>
>
>
>
>
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss...@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
>


--
Luboš Doležel

0 new messages