iOS 中的 @synchronize(self)

本文探讨了Objective-C中使用的同步机制,特别是@synchronized与NSLock之间的相似性和差异。通过具体的代码示例,解释了@synchronized如何被编译器转换为底层的mutex操作,并对比了这两种锁机制的工作原理。

The Objective-C language level synchronization uses the mutex, just like NSLock does. Semantically there are some small technical differences, but it is basically correct to think of them as two seperate interface implemented on top of a common (more primitive) entity.

In particular with an NSLock you have an explicit lock whereas with @synchronize you have an implicit lock associated with the object you are using to synchronize. The benefit of the language level locking is the compiler understands it so it can deal with scoping issues, but mechanically they behave basically the same.

You can think of @synchronize as basically a compiler rewrite:

- (NSString *)myString {
 
@synchronized(self) {
   
return [[myString retain] autorelease];
 
}
}

is transformed into:

- (NSString *)myString {
 
NSString *retval = nil;
  pthread_mutex_t
*self_mutex = LOOK_UP_MUTEX(self);
  pthread_mutex_lock
(self_mutex);
  retval
= [[myString retain] autorelease];
  pthread_mutex_unlock
(self_mutex);
 
return retval;
}

That is not exactly correct because the actual transform is more complex and uses recursive locks, but it should get the point across.

下载代码方式:https://pan.quark.cn/s/604a73f2a5f9 流量分类机制(IEEE 802.1Qbv)将以太网数据传输划分为多个不同类别,每个类别均被分配特定时段以获取网络访问权,借此构建了类别专属的保护“路径”。依托IEEE 802.1Qcc的优化SRP与性能提升,用户网络接口(UNI)得到扩充,从而支持了远程集中化的网络设置。 ### IEEE 802.1Qbv TSN:流量调度技术详解 #### 一、IEEE 802.1Qbv TSN概述 在当前迅速演进的科技领域中,特别是工业自动化、汽车电子以及高性能计算等领域对实时通信的需求持续上升,时间敏感型网络(Time-Sensitive Networking, TSN)技术随之出现。其中,IEEE 802.1Qbv规范是TSN体系中的一个关键构成,主要聚焦于以太网中时间敏感数据流量的管理与调度。 #### 二、IEEE 802.1Qbv标准背景 IEEE 802.1Qbv由IEEE LAN/MAN标准委员会制定,作为IEEE 802.1Q-2014规范的一个延伸,目的是为支持定时传输的数据单元提供更高效、更精准的服务。该规范通过引入时间敏感的流量调度机制,使网络能更好地适应工业控制等环境下的实时性要求。 #### 三、核心概念阐释 **1. 流量调度(Scheduled Traffic)** - **定义**:IEEE 802.1Qbv的核心功能之一是流量调度,它允许依据预定的时间计划来传输不同类型的网络数据。 - **作用**:通过设定优先级和分配时间间隙,保障关键任务数据单元能在规定时限内完成传输,从而增强整个网络的可靠性与确定性。 **2. 类别特定的保护“路径”** - **...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值