欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

ios之線程安全

iphone @synchronized

(2011-10-14 00:07:12) 
ios之線程安全轉(zhuǎn)載
標(biāo)簽: 

雜談

分類:iOS

@synchronized(self) {} 這種寫法是什么作用?


如題:

@synchronized(self) {
。。。 。。。
}

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到鐘祥網(wǎng)站設(shè)計(jì)與鐘祥網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋鐘祥地區(qū)。

保證此時(shí)沒(méi)有其他線程對(duì)self對(duì)象進(jìn)行修改

Using the @synchronized Directive
The @synchronized directive is a convenient way to create mutex locks on the fly in Objective-C code. The @synchronized directive does what any other mutex lock would do—it prevents different threads from acquiring the same lock at the same time. In this case, however, you do not have to create the mutex or lock object directly. Instead, you simply use any Objective-C object as a lock token, as shown in the following example:

- (void)myMethod:(id)anObj
{
@synchronized(anObj)
{
// Everything between the braces is protected by the @synchronized directive.
}
}
The object passed to the @synchronized directive is a unique identifier used to distinguish the protected block. If you execute the preceding method in two different threads, passing a different object for the anObj parameter on each thread, each would take its lock and continue processing without being blocked by the other. If you pass the same object in both cases, however, one of the threads would acquire the lock first and the other would block until the first thread completed the critical section.

As a precautionary measure, the @synchronized block implicitly adds an exception handler to the protected code. This handler automatically releases the mutex in the event that an exception is thrown. This means that in order to use the @synchronized directive, you must also enable Objective-C exception handling in your code. If you do not want the additional overhead caused by the implicit exception handler, you should consider using the lock classes.


For more information about the @synchronized directive, see The Objective-C Programming Language.

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 are the 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);
returnretval;
}

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

 

網(wǎng)頁(yè)名稱:ios之線程安全
當(dāng)前網(wǎng)址:http://aaarwkj.com/article46/igdphg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、靜態(tài)網(wǎng)站外貿(mào)網(wǎng)站建設(shè)、域名注冊(cè)、品牌網(wǎng)站設(shè)計(jì)、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管
日韩在线一区二区视频观看| 内射小美女阴户毛片在线| 欧美电影剧情av在线| 亚洲激情中文字幕av网| 播放欧美日韩特黄大片| 欧美老熟妇一区二区三区| 日本黄色一区二区三区四区| 日本一区二区三区高清不卡| 日韩精品一区二区三区电影在线播放| 内射嫩国产欧美国产日韩欧美| 亚洲成av人片又粗又长| 女子张开腿让男人捅爽| 激情五月婷婷久久av| 欧美日韩一级性生活片| 国产欧美日韩另类视频| 免费av中文字幕电影| 99久热在线精品视频| 最新91熟女九色地址| 日韩欧美国产麻豆91在线精品| 国产高清毛片区1区二区三区| 中文人妻熟妇乱又伦精品| 日本一区二区裸体视频| 国产99久久精品免费看| 国产一区二区伦理视频| 亚洲无综合素人在线观看| 免费可以看的黄片欧美| 日本一区二区三区播放| 蜜臀在线免费观看黄片视频| 亚洲成人乱码一区二区| 国产精品亚洲国产精品| 欧美一区二区日本国产激情| 日本在线不卡一区二区| 国产经典三级在线看| 欧美一区二区三区高清在线| 亚洲精品乱码精品乱码不卡| 最近免费欧美一级黄片| 日韩亚洲一区二区免费| 免费欧美一级黄片播放| 一区二区在线视频国产| 日本激情诱惑免费在线播放| 花花草草寻亲记在哪里免费看|