Re: NSTableDataSources and multi-threading
Re: NSTableDataSources and multi-threading
- Subject: Re: NSTableDataSources and multi-threading
- From: Shawn Erickson <email@hidden>
- Date: Tue, 4 Nov 2003 22:11:42 -0800
On Nov 4, 2003, at 8:43 PM, Nick Zitzmann wrote:
On Nov 4, 2003, at 12:11 AM, Sean Gilbertson wrote:
I have a data source, whose represented data is updated by several
threads. Because of this, the result of numberOfRowsInTableView: may
not be valid by the time tableView:objectValueForTableColumn:row: is
called. I have tried several ways of making sure that this does not
occur, including subclassing NSTableView and notifying the data
source when reloadData is called, but of course that is not the
appropriate place to look for redrawing of the table view; it is an
auxiliary method. Of course, I am using locks, but they are almost
worthless unless I can actually guarantee incorrupt output.
The way I fixed this with one project was to add a lock object, use
PB's Find window to point out each place in the code that the data
source was being accessed, and then add balancing lock and unlock
calls to each place. It's pretty much the only way to do what you want
to do...
Nick, if I understand what you as saying above the locking you are
suggesting is to granular and will not avoid the issue Sean is talking
about. What is needed is a way to insure that the data source isn't
updated while table data is being reloaded by the table view. I assume
Sean is worried about being asked about a row that doesn't exist any
longer.
As it stands I don't think a way exists for the data source
(controller) to know what is needed without subclassing of NSTableView.
Sean, are your threads inserting and/or removing rows? If they are only
appending rows to the data source then you should not have an issue,
just use noteNumberOfRowsChanged.
Otherwise I would consider modifying your data source on the main
thread only (possibly in bursts, queuing in your background threads a
little). This will insure that your view isn't updating at the same
time that your data source is changing. Look at using NSObject's
performSelectorOnMainThread.
-Shawn
_______________________________________________
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.