Xcode 调度全局队列崩溃

Xcode 调度全局队列崩溃,xcode,multithreading,queue,Xcode,Multithreading,Queue,因此,我有一个应用程序,它做了大量的数学运算,但它只有在我使用全局调度队列来处理多线程时才会崩溃。我想我可能做错了。有人能解释为什么这会导致撞车吗?或者至少我可以试着调试它 如果我这样做,它会很好地打印出答案。我已经用仪器检查了代码,它没有泄漏或任何东西 NSStringEncoding encoding; NSError *error; //Read in data file NSString *Data1FileContent = [NSString stringWithContentsO

因此,我有一个应用程序,它做了大量的数学运算,但它只有在我使用全局调度队列来处理多线程时才会崩溃。我想我可能做错了。有人能解释为什么这会导致撞车吗?或者至少我可以试着调试它

如果我这样做,它会很好地打印出答案。我已经用仪器检查了代码,它没有泄漏或任何东西

NSStringEncoding encoding;
NSError *error;

//Read in data file
NSString *Data1FileContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data1" ofType:@"txt"] usedEncoding:&encoding error:&error];
NSMutableArray *strides = [[Data1FileContent componentsSeparatedByString:@"\n"] mutableCopy];

//Read in data file
NSString *Data2FileContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data2" ofType:@"txt"] usedEncoding:&encoding error:&error];
NSMutableArray *gaitTimes = [[Data2FileContent componentsSeparatedByString:@"\n"] mutableCopy];

//Math
NSMutableArray *result = [gaitlyapunov gaitlyapunov:strides withTimeSteps:gaitTimes withFreq:150 withSegmentApproach:@"strides"];

NSLog(@"result = %@", result);

[gaitTimes release];
[strides release];

});
但是,当我试图在代码中更新UILabel时,它会导致崩溃

错误:

(lldb) //Thrown randomly in the math
导致问题的代码:

//Create a queue
dispatch_async(dispatch_get_global_queue(0, 0), ^{

    //This prints out fine
    dispatch_async(dispatch_get_main_queue(), ^{
        statusText.text = [NSString stringWithFormat:@"processing..."];
    });


NSStringEncoding encoding;
NSError *error;

//Read data
NSString *Data1FileContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data1" ofType:@"txt"] usedEncoding:&encoding error:&error];
NSMutableArray *strides = [[Data1FileContent componentsSeparatedByString:@"\n"] mutableCopy];

//Read data
NSString *Data2FileContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data2" ofType:@"txt"] usedEncoding:&encoding error:&error];
NSMutableArray *gaitTimes = [[Data2FileContent componentsSeparatedByString:@"\n"] mutableCopy];

//Math, that causes crash in this code only
NSMutableArray *result = [gaitlyapunov gaitlyapunov:strides withTimeSteps:gaitTimes withFreq:150 withSegmentApproach:@"strides"];

    //This should print the result into the label
    dispatch_async(dispatch_get_main_queue(), ^{
            statusText.text = [NSString stringWithFormat: @"result: %@", result];
    });

[gaitTimes release];
[strides release];

});

我追踪到了一个非线程安全编程问题。有关更多信息,请参见此处: