Linux thread synchronization

I am new to linux and linux streams. I spent some time searching on Google to understand the differences between all the features available for stream synchronization. I still have some questions.

I found all these different types of synchronization, each of which has a number of functions for locking, unlocking, checking locks, etc.

  • gcc atomic operations
  • futexes
  • mutexes
  • Deadlocks
  • seqlocks
  • rculocks
  • conditions
  • semaphores

My current (but probably erroneous) understanding is this:

semaphores are wide processes that are related to the file system (practically I guess) and are probably the slowest.

Futexes , , , seqlocks rculocks. Futexes , , .

Spinlocks , , . , (). . .

seq , , , . .

, , . . (mutex, futex, spin, seq, rcu) .

:

  • ?

  • - ? parallelism , . - . , . .

  • ( ) ... , . ? CPU ? , . , , , , , , . , . , , , ... .

  • ... , ... ? (spin/seq locks), "irq".

  • ?

  • - , , , - ? , . , , , . .

  • futexes? ?

  • , , ?

  • gcc atomic ops, test_and_set, , , test_and_set ? , , . , , . , 0. , . . , , 1. 1, , . , __set . , test_and_set 500 cpu , , cpu L2 /.... - 1 .... , 500 1, , .... .

-, , SYSTEM ( Jsut CPU) . gcc atomic ops . : , , (0 = , 1 = ). test_and_set , . .

!

+5
5

, . gcc . 2 , , , , , ( , ...). pthread_create, attr, cancel kill. pthread_kill, , , . 40 , cond_wait. ... pthreads_mutexes, .

+2

, , posix. , man-,

man pthread_mutex_init
man pthread_rwlock_init
man pthread_spin_init

, , , .

, . , , , , .

+2

# 8 , , , ? , , aproach sem_post() sem_wait "semaphore.h"

0

  • Pthreads: POSIX

  • POSIX (R)
0

futexes - . futex ​​ , , .

futex (PDF), . , , , pthread.

easy, .

0

All Articles