申し訳ありません...残念-デバッグモードを実行しなかったため、エラーが間違った行に表示されました。デバッグモードで正しい行を表示すると、エラーは単純な「境界外の配列にアクセスしない」でした-エラー(タイプミス-ある配列を参照しましたが、別の配列へのアクセスでした)
別のスレッドから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
- なぜ同期しないのですか?!他に何が起こっている可能性がありますか?