Using Share Memory on Hash Table

377 views
Skip to first unread message

Nitish Moleshwari

unread,
Nov 19, 2016, 5:40:42 AM11/19/16
to uthash
Hi,

I am trying to keep my Hash table in a Shared Memory  which can be shared along multiple processes. I am able to open my shared memory and add Hash table  successfully but while closing my shared memory i am getting error of : Invalid argument . 

I am using General macro for adding and finding hash.I hope to hear from you .

Thank You,
Nitish G. Moleshwari
 

Arthur O'Dwyer

unread,
Nov 19, 2016, 6:07:46 PM11/19/16
to uth...@googlegroups.com, ntsh....@gmail.com
I don't think this question has anything to do with uthash.
Here's the first Google result for "Invalid argument shared memory"; hope it helps! (If not, some of the other results probably will.)

–Arthur


--
You received this message because you are subscribed to the Google Groups "uthash" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uthash+unsubscribe@googlegroups.com.
To post to this group, send email to uth...@googlegroups.com.
Visit this group at https://groups.google.com/group/uthash.
For more options, visit https://groups.google.com/d/optout.

Nitish Moleshwari

unread,
Nov 21, 2016, 1:56:42 AM11/21/16
to uthash
Hi,

Is there any way, i can share my uthash table with multiple processes? My procedure will be , one process on start will create and  add the  hash table and after this other processes will make changes in that same hash table . 

Please let me know any solution on this.

Thanking You,
Nitish Moleshwari

Arthur O'Dwyer

unread,
Nov 21, 2016, 6:34:11 PM11/21/16
to uth...@googlegroups.com, ntsh....@gmail.com
Nitish,

Read these:
http://www.cse.psu.edu/~deh25/cmpsc473/notes/OSC/Processes/shm.html

However, be warned that:
- Concurrent accesses to shared resources must be guarded by a mutex
- You'll need to figure out whose responsibility it is to initialize the shared hash; if this requires a shared mutex, then you'll need to figure out whose responsibility it is to initialize the shared mutex, and so on
- All pointers that will be followed by both processes must point to objects located in the shared memory segment
- Not only that, but since uthash uses raw C pointers, both processes must agree on the LOCATION of the shared memory segment, e.g. by hard-coding the first argument to mmap()

This is all possible, but probably much harder than you ought to be tackling.

I've slapped together a quick(?) example using the POSIX shared-memory API; see the attached zipfile. Notice that it sets up a pthread_mutex_t to control access to the shared memory but then doesn't actually *use* that mutex, because I'm lazy. Also notice that I had to write my own memory allocator, which I did in as lazy a way as possible (e.g. SharedTable_free() is a no-op).

HTH,
Arthur



--
uthash-shm-example.zip
Reply all
Reply to author
Forward
0 new messages