Concurrency: DataSource modified while TableView is displaying data
Concurrency: DataSource modified while TableView is displaying data
- Subject: Concurrency: DataSource modified while TableView is displaying data
- From: Jean Suisse <email@hidden>
- Date: Wed, 25 Apr 2012 13:08:03 +0200
Hi All,
I have an NSTableView whose DataSource and delegate is a custom controller <NSTableViewDataSource, NSTableViewDelegate> holding an NSMutableArray (containing a list of "Task/job" objects).
The tableView is used to display "Tasks" waiting to be executed. When activated, the "Task" is requested to post its blocks on a serial queue by the controller.
The last block posted by all tasks will actually notify (objC message) the controller that the task has ended. The controller will remove the task from the list and request the NSTableView to reload its data. This, I presume, is executed from the serial queue.
Sometimes, I get an out of bounds exception from my data source (the NSMutableArray owned by the controller).
I am thinking:
The issue is that, sometimes, between the time the NSMutableArray is requested to remove an object and the time the tableView is requested to reload its data, some external event (rare) may trigger a redraw. The tableView, unaware that one element is now missing, requests from the data source an element whose row number is equal to the datasource's count (=> out of bounds by 1 index).
What's troubling me:
When stepping through the programming with the debugger, I plainly see that the tableView has requested the number of elements in the datasource half a dozen of times before making the mistake of requesting an out-of-bounds element (thus, the tableview should be well aware of the new count).
Currently, every modification of the datasource is immediately followed by a reloadData request to the tableView. Is there a way to ensure that these two consecutive calls are executed without the processor switching to an other thread ?
Cheers,
Jean
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden