I have a project that I am working on. This is basically an extension of that. There is this weird error (Seg fault) when I run this code. What makes this error weird is that I print the value stored in the pointer and in the next line I pass that in a function at the curly braces where the function starts it throws an error saying "Cannot access memory location". GDB shows that a new thread was being created, I believe that thread invalidated the memory but the question is why. I have no clue. Appreciate your help. It's lots of files there so you can check it out using following command if you have svn installed:
svn checkout http://logic-simulator.googlecode.com/svn/trunk/ logic-simulator-read-only

The error is when we call InsertItems function. Thanks for looking.

when u create a new thread it usually cannot access the memory allotted to other process including its parent. U need to use shared memory or other IPC for communication. I may not be correct totally but this is an IPC issue. Read on how to communicate between diferent processes.

Thanks for your response. However, I am not creating a PThread here. It is getting created automatically. The error is way before I create it.
I print something like this:
fprintf(stderr, "inserting i =%d r = %d address=%p value=%d \n",i,r, &(InitMessages[i*r]),(&(InitMessages[i*r]))->item);

And it prints the values properly that means Initmessages is a valid pointer and accessible.
Now I call a function like this:
InsertItems(&(InitMessages[i*r]),r);
Basically, Initmessgaes has multiple of r items. Every time I call InsertItems I pass address of first item in the chunk of next r items. This function throws error that memory can not be accessed. I do not understand what is wrong as I can print the value and then send it. How could this be invalidated?
You can see the entire code by running above svn command to check out the project. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.