Re: malloc/free problems within a thread
Re: malloc/free problems within a thread
- Subject: Re: malloc/free problems within a thread
- From: Ken Tozier <email@hidden>
- Date: Sat, 29 Jul 2006 18:55:00 -0400
On Jul 29, 2006, at 6:43 PM, stephen joseph butler wrote:
Every 5 seconds you're creating a helper thread that will perform a 12
minute directory scan. See where I'm going with this?
There's more to it than the snippet shows but I get the drift.
Yes. You're spawning multiple threads, all of which are trying to
access the same mutable array without any sort of locking. This is
will most certainly cause random memory corruption.
You have a couple options:
1) allocate an NSLock along with the NSMutableArray and synchronize
access to your collection.
2) allocate a temporary NSMutableArray inside scanDirectoriesInThread:
and only after you're done assign it to holdingBin. However, you'll
want to release whatever's there, so you need a lock for holdingBin to
make sure you have exclusive access. That is...
[holdingBin lock];
[holdingBin release]; holdingBin = nil;
holdingBin = tempArray;
[holdingBin unlock];
Thanks Joseph I'll look into locks
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden