日本有码中文字幕视频,在线能看三级网站,日本妇乱子伦视频免费的,中文字幕一页在线

      synchronized鎖升級(synchronized用法)

      時間:2022-10-06 12:36:32來源:
      導讀您好,現(xiàn)在蔡蔡來為大家解答以上的問題。synchronized鎖升級,synchronized用法相信很多小伙伴還不知道,現(xiàn)在讓我們一起來看看吧!1、保證此...

      您好,現(xiàn)在蔡蔡來為大家解答以上的問題。synchronized鎖升級,synchronized用法相信很多小伙伴還不知道,現(xiàn)在讓我們一起來看看吧!

      1、保證此時沒有其他線程對self對象進行修改Using the @synchronized DirectiveThe @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.。

      本文就為大家分享到這里,希望小伙伴們會喜歡。

      標簽:
      最新文章