Thread: mutex and padding ?!

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251

    mutex and padding ?!

    Using pthreads on a Linux platform, ordinary Pentium x86 guess 32 bit registers

    (1)
    a structure or array is shared but each single element of the array, or field of the structure, is not shared.

    Example :
    pthread 1 uses only Struct[0].field1 , Struct[0].field2 and Struct[1].field3
    pthread 2 uses only Struct[1].field1 and Struct[0].field3

    If any of field1, field2 or field3 has not size = multiple of 4 bytes the struct is not safe if I do not use mutex??

    (2)
    can I define mutex[10]
    and let
    mutex[0] be used by thread1 and thread2
    mutex[1] be used by thread3 and thread4
    etc. ?
    If on a machine mutex has size not multiple of 4 byte will potentially threads3 and 2 for instance interfere?!

    Thanks

    Kind regards,
    Last edited by mynickmynick; 06-30-2008 at 11:11 AM.

  2. #2

Popular pages Recent additions subscribe to a feed