---
title: lock()
framework: coredata
role: symbol
role_heading: Instance Method
path: coredata/nspersistentstorecoordinator/lock()
---

# lock()

Attempts to acquire a lock.

## Declaration

```swift
func lock()
```

## Discussion

Discussion This method blocks a thread’s execution until the lock can be acquired. An application protects a critical section of code by requiring a thread to acquire a lock before executing the code. Once the critical section is past, the thread relinquishes the lock by invoking unlock.

## See Also

### Deprecated instance methods

- [addPersistentStore(ofType:configurationName:at:options:)](coredata/nspersistentstorecoordinator/addpersistentstore(oftype:configurationname:at:options:).md)
- [destroyPersistentStore(at:ofType:options:)](coredata/nspersistentstorecoordinator/destroypersistentstore(at:oftype:options:).md)
- [importStore(withIdentifier:fromExternalRecordsDirectoryAt:to:options:ofType:)](coredata/nspersistentstorecoordinator/importstore(withidentifier:fromexternalrecordsdirectoryat:to:options:oftype:).md)
- [migratePersistentStore(_:to:options:withType:)](coredata/nspersistentstorecoordinator/migratepersistentstore(_:to:options:withtype:).md)
- [replacePersistentStore(at:destinationOptions:withPersistentStoreFrom:sourceOptions:ofType:)](coredata/nspersistentstorecoordinator/replacepersistentstore(at:destinationoptions:withpersistentstorefrom:sourceoptions:oftype:).md)
- [tryLock()](coredata/nspersistentstorecoordinator/trylock().md)
- [unlock()](coredata/nspersistentstorecoordinator/unlock().md)
- [perform(_:)](coredata/nspersistentstorecoordinator/perform(_:)-7jqb.md)
- [performAndWait(_:)](coredata/nspersistentstorecoordinator/performandwait(_:)-d3kq.md)
