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
Iphone 在后台处理两个队列_Iphone_Multithreading_Ios7 - Fatal编程技术网

Iphone 在后台处理两个队列

Iphone 在后台处理两个队列,iphone,multithreading,ios7,Iphone,Multithreading,Ios7,我是Iphone开发方面的新手,正在研究线程技术 我创建了如下两个队列: dispatch_queue_t **Queue1** = dispatch_queue_create("Queue1", NULL); dispatch_queue_t **Queue2** = dispatch_queue_create("Queue2", NULL); dispatch_async(**Queue1**, ^{ [self HandleDownloadResponse]; }); dispa

我是Iphone开发方面的新手,正在研究线程技术

我创建了如下两个队列:

dispatch_queue_t **Queue1** = dispatch_queue_create("Queue1", NULL);

dispatch_queue_t **Queue2** = dispatch_queue_create("Queue2", NULL);
dispatch_async(**Queue1**, ^{

[self HandleDownloadResponse];

});

dispatch_async(**Queue1**, ^{
    dispatch_async(dispatch_get_main_queue(), ^{

});

});
我在Queue1中添加了如下任务:

dispatch_queue_t **Queue1** = dispatch_queue_create("Queue1", NULL);

dispatch_queue_t **Queue2** = dispatch_queue_create("Queue2", NULL);
dispatch_async(**Queue1**, ^{

[self HandleDownloadResponse];

});

dispatch_async(**Queue1**, ^{
    dispatch_async(dispatch_get_main_queue(), ^{

});

});
当我获得web服务的响应时,将执行队列1,它使用Sqllite3数据库

当我的数据从我的设备传输时,将执行队列2,并使用sqllite3

我的问题是:当我在数据传输开始前第一次得到web服务响应时,我得到了一个数据库锁错误

因此,当我的队列2处于活动状态时,我想暂停(睡眠)我的队列1。我该怎么做?

你可以试试这个

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // response from webservice
     dispatch_async(dispatch_get_main_queue(), ^{
     //insert into database

    }
    }

尝试使用互斥访问数据库。可能它会直接解决您的问题。我正在执行两个任务,一个用于从数据库读取数据的UI显示,另一个任务是对数据库执行写入操作。因此,我使用了NOMUTEX。因此,当其中一个操作完成时,您的数据库应该被锁定,相互退出(或锁定,它们是相同的)在这种情况下可能会有所帮助。这可能会有助于您阅读:我不能在主线程上工作,因为我的主线程在UI上工作以显示数据传输进度。