FROM : Alex Esplin
DATE : Thu May 15 07:15:34 2008
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
DATE : Thu May 15 07:15:34 2008
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
| Related mails | Author | Date |
|---|---|---|
| Alex Esplin | May 15, 07:15 | |
| Bill Bumgarner | May 15, 07:25 | |
| Ken Thomases | May 15, 07:26 | |
| Alex Esplin | May 15, 08:02 | |
| Ken Thomases | May 15, 10:03 | |
| Michael Vannorsdel | May 15, 10:09 |






Cocoa mail archive

