Multithreading and Memory on HP-UX (Posix Threads)

When a program creates detached threads (using Posix threads), does the new thread inherit the memory space of the parent?  I am creating the threads detached, but when I try to use some memory that was created by the parent thread, the program crashes with a memory error.  Do processes need to be created not detached (attached) in order to use the parent's memory space?  I am compiling this C++ code with gcc 3.4.2 on an HP-UX 11.00 32 bit machine.  The exact code works on both Linux and Solaris, so I'm wondering if this is an HPUX problem or something that I just got away with on the other 2 OS's.   Here is how I"m creating the threads:

      pthread_t tid;
      pthread_attr_t thAttrs;
      pthread_attr_setdetachstate(&thAttrs, PTHREAD_CREATE_DETACHED);
      int ret = pthread_create(&tid, &thAttrs, MyFunc, (void *)myPtr);

If I run the exact code single threaded, the crash disappears.  Any help is appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

By definition, all threads have access to the entire address space of the process.
However, this full access means that the threads can have 'collisions' - reading
and/or writing the same memory location at the same time, corrupting data.
For that reason, threads programming usually requires the use of thread coordination
primitives such as mutexes, semaphores, condition variables, and critical sections.
These allow threads to coordinate access to common data, signal each other,
sleep and wake up, etc.  Consider one of these threads programming tutorial.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mromeoAuthor Commented:
I am using mutexes to prevent these kinds of collisions.  In addition, my early testing only involves creating a single thread (in addition to the parent).  When I take the calls to pthread_xxx out, the program works fine.  When I put them back in, it crashes.  It seems to crash when it is in an idle state.
mromeoAuthor Commented:
And like I said earlier, the exact code works great on both Linux and SunOS.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.