Re: Objects between threads
Re: Objects between threads
- Subject: Re: Objects between threads
- From: Jay Prince <email@hidden>
- Date: Sun, 8 Sep 2002 02:07:14 -0700
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.
On Saturday, September 7, 2002, at 08:28 am, Nathan Day wrote:
You don't mention the use of NSLock, NSMutableArray's are not thread
safe so you need to restrict access to your array to one thread at a
time using NSLock.
On Sunday, September 8, 2002, at 12:17 AM, Chris Ross wrote:
I have a problem. I have a class that can connect to a data source.
I wish to loop around and go through an array of the data source
objects checking to see if there is any data, and if so process it.
If I create an object and add it to an array from an outside thread,
then the program segfaults when I try and access the object, and
it's methods. If I create the object within the thread and add it to
the same array, everything works fine. The array is created out
side the threads execution pool.
Any ideas on how to get this to work ? I am using a thread so that
data processing can occur outside the main application loop.
I guess that it has something to do with memory pools but I dont
know, I am too new at this,
Nathan Day
http://homepage.mac.com/nathan_day/
_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev
_______________________________________________
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.