• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
any help with [NSThread initWithTarget:selector:object]???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

any help with [NSThread initWithTarget:selector:object]???


  • Subject: any help with [NSThread initWithTarget:selector:object]???
  • From: "Alex Esplin" <email@hidden>
  • Date: Wed, 14 May 2008 23:15:34 -0600

Hey all,

Sorry if this has been answered before, I've been googling and not
coming up with a direct answer to my problem.

I'm working on a (should be) trivial Vote Counter program for a class.
 I've elected to implement the project in Objective-C/Foundation
because I already know how to do something like this in C and I'd like
to learn something new.

I have a VoteList class that multiple threads will be adding votes to.
 I have locks around the code that adds a Vote to the list, so only
one thread can add a Vote at a time.  In testing this class, I'm
trying to start 4 threads that will add some votes to the list so I
can test the locks and make sure everything is getting counted.
Here's the relevant code:

NSLog(@"\n\n========== testVoteList Phase 2 ==========\n\n");
list2 = [[VoteList alloc] init];
NSThread* thread1 = [[NSThread alloc] initWithTarget:self
selector:@selector(phase2:) object:list2];
NSThread* thread2 = [[NSThread alloc] initWithTarget:self
selector:@selector(phase2:) object:list2];
NSThread* thread3 = [[NSThread alloc] initWithTarget:self
selector:@selector(phase2:) object:list2];
NSThread* thread4 = [[NSThread alloc] initWithTarget:self
selector:@selector(phase2:) object:list2];

[thread1 start];
[thread2 start];
[thread3 start];
[thread4 start];

The selector(phase2:) is here:

-(void) phase2: (id) arg {
	VoteList* list = arg;
	NSLog(@"Thread checking in...");
	printf("Thread checking in...\n");

	return;
}

Everything compiles, and when I run it, the Console tells me that
debugging completed normally.  However, I'm getting nothing in the way
of output from any of the threads:

========== testVoteList Phase 2 ==========


The Debugger has exited with status 0.


Any ideas?

Thanks
--
Alex Esplin
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: any help with [NSThread initWithTarget:selector:object]???
      • From: Ken Thomases <email@hidden>
    • Re: any help with [NSThread initWithTarget:selector:object]???
      • From: Bill Bumgarner <email@hidden>
  • Prev by Date: Re: basic bindings question
  • Next by Date: Re: Guidance for Cocoa's steep learning curve
  • Previous by thread: [ANN] DrawKit beta 3 now available
  • Next by thread: Re: any help with [NSThread initWithTarget:selector:object]???
  • Index(es):
    • Date
    • Thread