Re: Crash in pthread_mutex_lock
Re: Crash in pthread_mutex_lock
- Subject: Re: Crash in pthread_mutex_lock
- From: Jeremy Sagan <email@hidden>
- Date: Sun, 12 Jun 2005 19:06:16 -0400
Just a followup on this thread for anyone who has a similar problem.
I resolved this problem by first trying a local variable for the
threaddata and that worked. I then verified the address passed to
pthread_mutex_lock and it was not zero and was indeed the exact address
of the variable in my address space. Hmmm... then I noticed that the
crashing instruction was a lwarx instruction. This instruction requires
that the address be on a 4 byte boundary or results will be
unpredictable.
The upshot is that the problem was an alignment issue easily fixed by
doing a align=power pragma before the structure definition.
Jeremy
On Jun 12, 2005, at 10:34 AM, Jeremy Sagan wrote:
Thank you Jonas for answering.
Here is my code. I verified with the debugger that mThreadInit is
called on the thread first. When ThreadLock is called mOwner is 0 and
then a crash occurs in pthread_mutex_lock.
Jeremy
typedef struct mThreadData
{
pthread_t mOwner;
pthread_mutex_t mMutex;
}mThreadData, *mThreadPtr;
OSStatus mThreadInit(mThreadPtr theThread)
{
OSStatus stat = pthread_mutex_init(&theThread->mMutex, NULL); //init
locking
theThread->mOwner = 0;
return (stat);
}
bool ThreadLock(mThreadPtr theThread)
{
pthread_t thisThread = pthread_self();
if (theThread->mOwner == thisThread)
return false; // already acquired
require_noerr(pthread_mutex_lock(&theThread->mMutex), done);
theThread->mOwner = thisThread;
return true; // did acquire lock
done:
return false; // error, didn't acquire lock
}
On Jun 12, 2005, at 4:31 AM, Jonas Maebe wrote:
On 12 Jun 2005, at 07:35, Jeremy Sagan wrote:
Now my major problem is that every call to pthread_mutex_lock
crashes with a EXC_Bad_ACCESS. I have tried changing the compiler
from 4.0 to 3.3 with no difference. The same call works fine when
compiled under codewarrior.
Are you calling pthread_mutex_init first, and if you pass an
attribute are you initialising that one as well? That the code works
fine when compiled with Codewarrior does not necessarily mean it's
correct. Different stack layouts can expose different bugs.
Jonas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden