對不起... 羞愧 - 我沒有運行調試模式,所以錯誤顯示在錯誤的行。在調試模式下,並且示出了右行,錯誤是一個簡單的「不訪問其邊界之外的陣列」 -error(錯字 - 我稱爲一個陣列,但是訪問是到另一個)NSMutableArray在多線程應用程序中出現SIGABRT ...但我做了@synchronized!
爲什麼當我從另一個線程清空NSMutableArray時,訪問NSMutableArray的計數會產生SIGABRT?我認爲@synchronized應該這樣做,因爲它的名字意味着什麼?
NSMutableArray *sourceImageRepArray;
...
@synchronized(self)
{
NSLog(@"singleton 1 %p", self);
unsigned long count = sourceImageRepArray.count; //SIGABRT here!
...
不知道有多少額外的代碼你要我分享......這是觸發它的代碼:
@synchronized([Singleton sharedSingleton])
{
NSLog(@"singleton 2 %p", [Singleton sharedSingleton]);
int i, n;
n = [filenames count];
for(i=0; i<n; i++){
ImageRep *item = [[ImageRep alloc] init];
[item setPath:[filenames objectAtIndex:i]];
[[Singleton sharedSingleton].targetImageRepArray insertObject:item atIndex: [targetImageBrowser indexAtLocationOfDroppedItem]];
[item release];
[[Singleton sharedSingleton] removeImageRepFromArray:[Singleton sharedSingleton].sourceImageRepArray withPath:[filenames objectAtIndex:i]];
}
}
單1 ==單2:
2011-02-08 07:22:03.265 Crash[60001:5d03] singleton 1 0x200047680
2011-02-08 07:22:03.433 Crash[60001:a0f] singleton 2 0x200047680
- 爲什麼它不同步?還有什麼可以繼續?
是的,正如我所說的singleton 1 == singleton 2.請參閱編輯。 – Torkel 2011-02-08 06:23:00