NSLock

Wongbing·2022년 10월 28일
0

Apple Docs

목록 보기
9/11
tags: 문서스터디

An object that coordinates the operation of multiple threads of execution within the same application.

동일한 애플리케이션 내에서 여러 실행 스레드의 작업을 조정하는 객체.

Declaration

class NSLock: NSObject

Overview

An NSLock object can be used to mediate access to an application's global data or to protect a critical section of code, allowing it to run atomically.

NSLock 객체는 앱의 global data으로의 접근을 중재하는 데에 사용 되거나, 중요한 코드섹션을 보호하여 atomically 하게 실행할 수 있도록 합니다.

Warning
The NSLock class uses POSIX threads to implement its locking behavior. When sending an unlock message to an NSLock object, you must be sure that message is sent from the same thread that sent the initial lock message.
Unlocking a lock from a different thread can result in undefined behavior

NSLock 클래스는 잠금동작을 구현하기 위해 POSIX 스레드를 사용합니다. NSLock 객체에 unlock 메세지를 보낸다면, 해당 메세지를 보낸 스레드가 처음 lock 메세지를 보냈던 스레드와 같아야 합니다. 다른 스레드에서 잠금을 해제한다면 결과적으로 오류가 발생할 것입니다.

You should not use this class to implement a recursive lock. Calling the lock method twice on the same thread will lock up your thread permanently. Use the NSRecursiveLock class to implement recursive locks instead.

재귀 잠금을 구현하기 위해서라면, 이 클래스를 사용하지 마십시오. 같은 스레드에서 lock 메서드를 두번 호출하게 되면 영구적으로 잠기게 됩니다. 재귀잠금을 구현하기 위해서는 NSRecursiveLock 클래스를 대신 사용하세요.

Unlocking a lock that is not locked is considered a programmer error and should be fixed in your code. The NSLock class reports such errors by printing an error message to the console when they occur.

잠기지 않은 것을 해제하는 것은 휴먼에러로 고려되며, 수정해야 합니다. NSLock 클래스는 이러한 에러가 발생했을 때 콘솔창에 에러메세지를 출력해서 보고합니다

profile
IOS 앱개발 공부

0개의 댓글