Re: NSTableView and threads...
Re: NSTableView and threads...
- Subject: Re: NSTableView and threads...
- From: Pontus Ilbring <email@hidden>
- Date: Fri, 18 Feb 2005 18:55:29 +0100
On 2005-02-18, at 05.54, Michael Burbidge wrote:
I have an NSTableView which contains a list of files. The files are
added to the list by dragging in from the finder. The files are
processed and removed from the list by a number of threads, which is
configurable. The table view has a data source, and in the data source
I override numberOfRowsInTableView: and
objectValueForTableColumn:row:. When files are added to the data
structure that the table view is a view of it is surrounded by a mutex
(lock). The problem I have is that I also need a mutex around the data
structure when the NSTableView accesses it via the two methods
numberOfRowsInTableView: and objectValueForTableColumn:row:. but I'm
not in control at that point. What happens is that in between the time
the table view calls the numberOfRowsInTableView: method and the
objectValueForTableColumn:row: method, files are deleted from the data
structure the table is viewing, by the threads that are processing the
files in the data structure. The result is an array index out of
bounds.
Is there anyway to use the NSTableView in a thread safe manner, where
threads may add or remove elements from the data structure the table
is viewing?
Do you really want to prevent the worker threads from getting data
while the main thread is updating the table view?
You could use two lists, a master list which the files are added to and
the threads get data from, and another list that serves as a data
source for the table view. Then make it the main thread's
responsibility to keep the data source list synched with the master
list, using a timer or what not. Since both the updating of the table
view and the synching of the data source execute in the main thread
those two will never interfere.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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