2011-02-07 56 views
0

對不起... 羞愧 - 我沒有運行調試模式,所以錯誤顯示在錯誤的行。在調試模式下,並且示出了右行,錯誤是一個簡單的「不訪問其邊界之外的陣列」 -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 
  • 爲什麼它不同步?還有什麼可以繼續?

回答

0

對不起... 羞愧 - 我沒有運行調試模式,所以錯誤顯示在錯誤的行上。在調試模式,並顯示正確的線,錯誤是一個簡單的「不訪問數組超出其界限」 - 錯誤(錯字 - 我指的是一個數組,但訪問到另一個)

所以解決我的問題是:

不要在版本中進行NSLog調試,它可能會在錯誤的行上標記錯誤。 (有時,在多線程應用程序中,我猜?)

0

你確定你的自己和[Singleton sharedSingleton]是同一個對象嗎?

+0

是的,正如我所說的singleton 1 == singleton 2.請參閱編輯。 – Torkel 2011-02-08 06:23:00

相關問題