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 10:34:05 -0400
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:
This email sent to email@hidden