3 Replies Latest reply: Sep 30, 2012 12:01 PM by 800381 RSS

    SPARC V8 pthread_mutex_t alignment

      KU 137111-01 (only link I found is 3rd party: http://tinyurl.com/ceet6ec) seems to indicate that the alignment requirement for pthread_mutex_t on SPARC V8 is on 8 bytes boundary. IIUC, such variables and types are correct wrt the new requirements:

      pthread_mutex_t g_mutex;
      struct S {
      pthread_mutex_t mutex_;
      static pthread_mutex_t s_mutex_;
      } s;

      Moreover, variables can be aligned using the #pragma align. The docs clearly indicate that the arguments to align must be variables, not types; also, that sometimes they must be indicated by their mangled name. Is my understanding correct?


      Edited by: 960802 on Sep 23, 2012 5:29 PM
        • 1. Re: SPARC V8 pthread_mutex_t alignment
          I'm not really sure what the question is.

          Yes, pthread_mutex_t is and must be aligned by 8.
          Yes, the align #pragma acts on variables, AFAIK,
          but you shouldn't need to use it.
          No, I did not click on your link.

          • 2. Re: SPARC V8 pthread_mutex_t alignment
            Thanks Peter.

            I thought I was being clever and courteous by not posting a long link, heh. Here is the complete link to a Fujitsu note about the patch: http://patches.ts.fujitsu.com/patch/sols/patch/137111-01_note-e.html Information about the mutex alignment is in the second half of the note/page.

            I have posted initially because I have received contradictory information about this topic in another forum and I wanted to clarify the issue. The information I received there was that a user must place alignment pragma's in the program to explicitly align pthread_mutex_t/mutex_t objects wherever they appear. E.g., the strongly suggested approach was like:

            #pragma pack(8)
            #pragma align 8(S)

            struct S {
            #pragma align 8(lock)
            mutex_t lock;

            I found it highly suspicious that Sun/Oracle would ask a user to explicitly align their mutex objects; also, I found it odd that the pragma docs do not mention aligning types (!).

            Thanks again.

            Edited by: 960802 on Sep 26, 2012 5:52 AM
            • 3. Re: SPARC V8 pthread_mutex_t alignment
              I've never seen any requirement to explicitly align mutex structures.

              That Fujitsu patch you linked to was to fix code that caused problems because it explicitly forced a mutex address off an 8-byte boundary.

              One wonders how on God's good Earth that ever made it past their testing. Heck, one wonders how it got past unit testing.