Attempting to access AsyncSocket instance from incorrect thread.
来源:互联网 发布:煤矿生产能力数据库 编辑:程序博客网 时间:2024/06/03 20:46
- (void)checkForThreadSafety方法,通过定义了#define DEBUG_THREAD_SAFETY 0 我们可以不启用这个方法,但是这样我们的socket就会不安全,因为asynsocket 本身是异步发送数据的,如果你在发送数据后,就清空内存,有可能会造成数据还未发送完,就被清空。我们该怎么办呢,我们可以开启一个信号量,
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_async(queue, ^{
[[SocketCommunication instance] socketWriteDate:sendData];
dispatch_semaphore_signal(semaphore);
});
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
if (newBu != NULL) {
free(newBu);
}
if (allData != NULL) {
free(allData);
}
大致就是这样子,不过为了支持多线程,还是用GCDSocket 比较好
- Attempting to access AsyncSocket instance from incorrect thread.
- java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be acce
- AsyncSocket EXC_BAD_ACCESS unrecognized selector sent to instance:0x6000001908e0
- Access denied attempting to launch a DCOM Server
- Memcache SchoonerSockIOPool-attempting to get SockIO from uninitialized pool! 问题
- You are attempting to build with the incorrect version of java.
- You are attempting to build with the incorrect version of java.
- You are attempting to build with the incorrect version of java
- You are attempting to build with the incorrect version of java.
- identifier of an instance ...... altered from ** to **
- 在eclipse中调试j2me程序出现ALERT: Attempting to resume current thread的问题
- Eclipse里不能调试J2ME程序的解决办法: Attempting to resume current thread
- Attempting to initialize hardware acceleration outside of the main thread 处理
- Server Application Unavailable (The web application you are attempting to access on this ..
- Server Application Unavailable --The web application you are attempting to access on this web server
- memcached 出现 Attempting to get SockIO from uninitialized pool!问题之根源
- ERROR com.schooner.MemCached.SchoonerSockIOPool - attempting to get SockIO from uninitialized pool
- How to access Excel from Perl
- ios加密后的数据保存本地,解密时为何失败
- FMDB 动态的添加数据
- 学习链接
- RSA加密原理
- 如何将数据保存到iphone中,app删除后,数据依然存在,
- Attempting to access AsyncSocket instance from incorrect thread.
- 《将博客搬至CSDN》
- Java学习笔记-窗口创建
- STM32F103命名规则
- Cygwin下安装SFTP Server
- 书
- 【转载】MFCC特征提取(C语言版本)
- Ubuntu 添加新分区 并设置挂载点
- session和cookie原理