对不起... 羞愧 - 我没有运行调试模式,所以错误显示在错误的行。在调试模式下,并且示出了右行,错误是一个简单的“不访问其边界之外的阵列” -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