Re: Objects between threads
Re: Objects between threads
- Subject: Re: Objects between threads
- From: Adam Thayer <email@hidden>
- Date: Sun, 08 Sep 2002 13:44:20 -0700
On 2002-09-08 02:07:14 -0700 Jay Prince <email@hidden> wrote:
I carefully used two NSMutableArrays, and created a timer. The timer causes the code getting the data to switch which arrays its reading into, and change a variable to indicate this. Then the thread that needs to read the data is spawned, and reads from the array. If the timer fires before the thread is finished, the switch doesn't happen. none of the code touches the array being read while the thread is doing its work. This way I don't have to worry about locks (Because I cannot have my primary thread blocked at any point). It only writes the other only reads the flag, and based on that, knows which array it can delete data from.
I would ask that you clarify why your main thread cannot block at any point. I have blocked my main thread plenty of times without affecting the performance of the thread. However, I also only lock around non-blocking code and around as little code as possible. This way even if thread #2 grabs the lock first, it is only in there for 1-2 lines of code, and unlocks in less than a millisecond. If you streamline code around that lock just right, you can be in and out of the lock before your main thread would get the CPU back anyways, which won't affect performance one bit.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.