Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading NSMUTABLEARRY在多线程应用程序中变为SIGABRT。。。但我正在做同步!_Multithreading_Cocoa_Nsmutablearray_Synchronized_Sigabrt - Fatal编程技术网

Multithreading NSMUTABLEARRY在多线程应用程序中变为SIGABRT。。。但我正在做同步!

Multithreading NSMUTABLEARRY在多线程应用程序中变为SIGABRT。。。但我正在做同步!,multithreading,cocoa,nsmutablearray,synchronized,sigabrt,Multithreading,Cocoa,Nsmutablearray,Synchronized,Sigabrt,对不起。。。羞愧-我没有运行调试模式,所以错误显示在错误的行上。在调试模式下,显示右边的一行,错误是一个简单的“不要访问超出其边界的数组”错误键入-我引用了一个数组,但访问了另一个数组 当我从另一个线程清空NSMutableArray时,为什么访问NSMutableArray的计数会产生SIGABRT?我以为@synchronized应该按照它的名字来做 NSMutableArray *sourceImageRepArray; ... @synchronized(self) { NSL

对不起。。。羞愧-我没有运行调试模式,所以错误显示在错误的行上。在调试模式下,显示右边的一行,错误是一个简单的“不要访问超出其边界的数组”错误键入-我引用了一个数组,但访问了另一个数组

当我从另一个线程清空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]];
   }
}
为什么不同步?!还可能发生什么?
你确定你自己和[Singleton sharedSingleton]是同一个对象吗?

对不起。。。羞愧-我没有运行调试模式,所以错误显示在错误的行上。在调试模式下,显示右边的一行,错误是一个简单的“不要访问超出其边界的数组”错误键入-我引用了一个数组,但访问了另一个数组

因此,我的问题的解决方案是:

不要在版本中进行NSLog调试,它可能会在错误的行上标记错误。有时候,在多线程应用程序中,我想

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