• 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
Thread crashing problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Thread crashing problem


  • Subject: Thread crashing problem
  • From: Ken Tozier <email@hidden>
  • Date: Mon, 22 Dec 2008 09:24:22 -0500

Hi

I wrote a little app to do deep folder watching on Windows servers from a Mac and am getting crashes when directories are added or removed from the watch directory. The directory scanning takes place in a thread and I tried to isolate the array from outside changes by locking it, but its still getting mutated out from underneath me.

Here's the method that executes in a thread

- (void) updateDirectoriesInThread:(id) inData
{
	NSLock		*lock = [[NSLock alloc] init];

	busy		= YES;

	if ([lock tryLock])
	{
		// allocate a new autorelease pool
		NSAutoreleasePool		*pool			= [[NSAutoreleasePool alloc] init];

		NSEnumerator			*enumerator		= [directories objectEnumerator];

		CNCDirectoryWatcher		*directory;

		while (directory = [enumerator nextObject])
		{
			[directory update];
		}

		// release the pool
		[pool release];

		[lock unlock];
	}

	busy					= NO;
}

And here are the mutator methods which can be called at any time by other threads

- (void) addDirectory:(CNCDirectoryWatcher *) inObserver
{
	[directories setObject: inObserver forKey: [inObserver directoryID]];
}

- (void) removeDirectory:(CNCDirectoryWatcher *) inObserver
{
	[directories removeObjectForKey: [inObserver directoryID]];
}


How do I get other threads to go into a holding pattern until the target thread is done enumerating the directories array? I want the other threads to be able to add their items without losing any data, just not until the target is done.


Any pointers appreciated
_______________________________________________

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: Thread crashing problem
      • From: Scott Ribe <email@hidden>
    • Re: Thread crashing problem
      • From: Ken Tozier <email@hidden>
  • Prev by Date: Re: warning: unused parameter '_value'
  • Next by Date: Re: Reliable way to capitalize camel-case strings? [SOLVED]
  • Previous by thread: Re: Saving the project
  • Next by thread: Re: Thread crashing problem
  • Index(es):
    • Date
    • Thread