A deadlock

Adding tasks to the current serial queue using sync freezes the current serial queue (resulting in a deadlock)

The lock

OSSpinLock (spin lock)

High-level lock

The thread waiting for the lock is busy and occupies CPU resources

Priority inversion can occur

os_unfair_lock

From the underlying call, the thread waiting for the OS_UNFAIR_LOCK lock is dormant, not busy, etc

Pthread_mutex (mutex)

Need to destroy

The mutex is normal
Recursive locking

Conditions for the lock
pthread_cond_t

pthread_cond_wait

pthread_cond_signal
Copy the code

NSLock

Pthread_mutex is encapsulated by default

NSRecursiveLock

NSCondition

Encapsulate NSConditionLock and NSCondition

wait

signal

SerialQueue

GCD serial queue

Semphore

@synthronized

A mutex recursive lock

Obj is passed into syncData (hashmap). Each obj corresponds to a lock (pmutext_lock). Obj corresponds to a recursive lock and then locks and unlocks it. It is used to represent a thread data, similar to a linked list structure, with a next pointer, and encapsulates a recursive_mutex_t attribute, confirming that @synchronized is indeed a recursive mutexCopy the code

Spinlocks are different from mutex

Spin-lock (not hibernated) The expected waiting time for the lock is short. CPU resources are not tense. Mutex The expected waiting time for the lock is longCopy the code

Read and write security

Atomic reads and writes are locked but release is not

Read write

Pthread_rwlock: read/write lock

Waiting locks go to sleepCopy the code

Dispatch_barrier_async: asynchronous fence function

A queue must be a manually created concurrent queueCopy the code