How to attach a linked list to the shared memory?

Hi all,

I have been working on shared memory. I have created the shared memory and a linked list of 5 nodes. Now I want to attach the linked list to shared memory. When we attach a shared memory it returns a void pointer, but here I am in a fix , how to relate this void pointer to linked list. So please help me out.

What do you mean by "attach the linked list to shared memory"? Do you want some region of shared memory to be in the linked list somehow, or do you want to create a linked list that resides in the shared memory so that other processes can use it?

If it's the latter, you need to "manage" the shared memory yourself and create the various data structures your linked list needs, moving them into shared memory where appropriate.

However, that seems like a fairly large undertaking - why do you want to do this?

John G

I am trying to access a linked list present in a shared memory by two threads simultaneously and just study the behaviour .

Just access it? Then someone else has created it, yes? There'll be a predefined way of getting access to the data structure (e.g. just casting the void* you get from shmat() & friends to a linked_list_t* or whatever), and then you can treat it like you would any other linked list.

Two threads in the same process already share memory, you don't need to set up a special shared memory area. If they were in different processes, you would.