Unix Technical Forum

pthread mutex and data alignment

This is a discussion on pthread mutex and data alignment within the AIX Operating System forums, part of the Unix Operating Systems category; --> Environment: AIX 4.3.3 - RS6000 H80 - VAC 5.0.2.0 Has anyone had data alignment problems when using pthreads while ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2008, 07:54 PM
T.R.Bennett
 
Posts: n/a
Default pthread mutex and data alignment

Environment:
AIX 4.3.3 - RS6000 H80 - VAC 5.0.2.0

Has anyone had data alignment problems when using
pthreads while compiling a program with the
"-qalign=packed" directive ????

Is this a known problem???

Our specific problem was in a pthread_mutex_trylock() call
.....it incorrectly reports the mutex is locked...
unless we force the pthread_mutex_t onto a full-word alignment...
....then it works correctly.

Are there other "subsystems" that have a similar problem ???

THANKS,
-tony
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-04-2008, 07:54 PM
Gary R. Hook
 
Posts: n/a
Default Re: pthread mutex and data alignment

Nicholas Dronen wrote:
> T.R.Bennett <bennett.tony@cnf.com> wrote:
> TRB> Has anyone had data alignment problems when using
> TRB> pthreads while compiling a program with the
> TRB> "-qalign=packed" directive ????


Sounds like the system include files should incorporate
wrappers that undo any alignment chosen by the user...

> TRB> Our specific problem was in a pthread_mutex_trylock() call
> TRB> ....it incorrectly reports the mutex is locked...
> TRB> unless we force the pthread_mutex_t onto a full-word alignment...
> TRB> ...then it works correctly.
>
> Whose problem it is depends on whether the mistake happens in the
> code (bad assumptions, bad data or variable access methods, whatnot)
> or the compiler (invalid behavior for pragma). You don't say under
> what exact circumstances the problem occurs. Do you have a small
> testcase that you can use to debug the problem outside of your
> application? If so, you have a chance to gather some information
> that might be useful for you or the vendor.
>
> And if the behavior disappears when you wrap your pthread code in
> '#pragma options align=reset', you're one step closer to knowing
> who to blame. :-)


It would probably make more sense to "stack" the pragma for
system structures, then "pop" back to the prior behavior.

> Small testcase. Try using 'reset'. Post what happens. Gary Hook,
> AKA Superfly of Linking, will respond. Eventually all will be well.
> (And Gary works for free. How much better can it get? :-)


Yeah, but I'm setting up a 1-900 number :-)

The packing pragma would nominally be applied to all of the code.
Unfortunately, certain system structures are going to have be
left alone. In this case, a lock had better be word aligned;
there are no options, no choices, no changes. Perhaps you
only need to wrap your structure definitions in the pack
pragma; the compiler should understand how to access the
members in that case, but that would leave the rest of the
system code alone.

--
Gary R. Hook / AIX PartnerWorld for Developers / These opinions are MINE
__________________________________________________ ______________________

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-04-2008, 07:55 PM
T.R.Bennett
 
Posts: n/a
Default Re: pthread mutex and data alignment

"Gary R. Hook" <nospam@nospammers.net> wrote in message news:<vaq1b.3019$Cp4.696@newssvr22.news.prodigy.co m>...
> Nicholas Dronen wrote:
> > T.R.Bennett <bennett.tony@cnf.com> wrote:
> > TRB> Has anyone had data alignment problems when using
> > TRB> pthreads while compiling a program with the
> > TRB> "-qalign=packed" directive ????

>
> Sounds like the system include files should incorporate
> wrappers that undo any alignment chosen by the user...
>
> > TRB> Our specific problem was in a pthread_mutex_trylock() call
> > TRB> ....it incorrectly reports the mutex is locked...
> > TRB> unless we force the pthread_mutex_t onto a full-word alignment...
> > TRB> ...then it works correctly.
> >
> > Whose problem it is depends on whether the mistake happens in the
> > code (bad assumptions, bad data or variable access methods, whatnot)
> > or the compiler (invalid behavior for pragma). You don't say under
> > what exact circumstances the problem occurs. Do you have a small
> > testcase that you can use to debug the problem outside of your
> > application? If so, you have a chance to gather some information
> > that might be useful for you or the vendor.
> >
> > And if the behavior disappears when you wrap your pthread code in
> > '#pragma options align=reset', you're one step closer to knowing
> > who to blame. :-)

>
> It would probably make more sense to "stack" the pragma for
> system structures, then "pop" back to the prior behavior.
>
> > Small testcase. Try using 'reset'. Post what happens. Gary Hook,
> > AKA Superfly of Linking, will respond. Eventually all will be well.
> > (And Gary works for free. How much better can it get? :-)

>
> Yeah, but I'm setting up a 1-900 number :-)
>
> The packing pragma would nominally be applied to all of the code.
> Unfortunately, certain system structures are going to have be
> left alone. In this case, a lock had better be word aligned;
> there are no options, no choices, no changes. Perhaps you
> only need to wrap your structure definitions in the pack
> pragma; the compiler should understand how to access the
> members in that case, but that would leave the rest of the
> system code alone.



Gary,

Thanks for the info.

Am I correct in my understanding that I should NOT use the "-qalign=packed"
compiler argument but instead should put "#pragma option align=packed"
in my source or include file before any structure I wish to have
packed, and follow those structures with a "#pragma option align=reset" ??

Also, am I correct in assuming that the "-qalign=packed" compiler command
line argument will override any "#pragma option align=-" directives
in my source and/or include files ???

-tony
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-04-2008, 07:57 PM
Gary R. Hook
 
Posts: n/a
Default Re: pthread mutex and data alignment

T.R.Bennett wrote:
> Am I correct in my understanding that I should NOT use the "-qalign=packed"
> compiler argument but instead should put "#pragma option align=packed"
> in my source or include file before any structure I wish to have
> packed, and follow those structures with a "#pragma option align=reset" ??


It is my understanding that this is the preferred technique.

> Also, am I correct in assuming that the "-qalign=packed" compiler command
> line argument will override any "#pragma option align=-" directives
> in my source and/or include files ???


I'd have to read the docs, but I would think this would be correct.

--
Gary R. Hook / AIX PartnerWorld for Developers / These opinions are MINE
__________________________________________________ ______________________

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:51 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com