Search code examples
cmultithreadinglockingstructuremutex

Lock pthread_mutex_t in structure C


I have one pthread_mutex_t aka lock in a structure and I create 2 structures.

  1. are those the same lock? Or are they a completely different lock?
  2. I have a function that uses the lock of the structure, can the one structure detect if the other structure lock is used?

Solution

  • are those the same lock?Or are they completly different lock?

    It deppends, if you have a pointer you can use the same mutex in both structures, if not, they are copies, using one will not reflect on the other.

    I have a function that uses the lock of the structure, can the one structure detect if the other structure lock is used?

    Again, if it's a pointer to the same mutex it's shared by both structures, lock/unlock is detected by both, if not, locking or unlocking one will have no effect on the other.