Avoid memory corruption in shared memory used by several processes?

S

Sune

Hi all,

I want to make data stored in-memory (not disk) available to several
processes. My concern is that poorly written C applications with
dangling pointers may(will) damage the data in this memory segment if
it is open to all, i.e. shared memory mapped into all processes memory
area.

I don't want to use TCP/IP client/server between the apps and a data
store process due to the overhead.

I don't want to start calculating checksums for all updates in a
shared memory area, since that means a lot of overhead.

Now my question:
Is it possible to expose just the interface of a data store component
and have that i/f shared between all processes who want to access the
data, and then have this shared interface make callbacks into a data
store process' private memory?

If yes, how do I achieve this? If not, why not?

Thanks for helping out
/Sune
 
U

user923005

Hi all,

I want to make data stored in-memory (not disk) available to several
processes. My concern is that poorly written C applications with
dangling pointers may(will) damage the data in this memory segment if
it is open to all, i.e. shared memory mapped into all processes memory
area.

I don't want to use TCP/IP client/server between the apps and a data
store process due to the overhead.

I don't want to start calculating checksums for all updates in a
shared memory area, since that means a lot of overhead.

Now my question:
Is it possible to expose just the interface of a data store component
and have that i/f shared between all processes who want to access the
data, and then have this shared interface make callbacks into a data
store process' private memory?

If yes, how do I achieve this? If not, why not?

Try news:comp.programming.threads
 
T

Thad Smith

Sune said:
I want to make data stored in-memory (not disk) available to several
processes. My concern is that poorly written C applications with
dangling pointers may(will) damage the data in this memory segment if
it is open to all, i.e. shared memory mapped into all processes memory
area.
...
Is it possible to expose just the interface of a data store component
and have that i/f shared between all processes who want to access the
data, and then have this shared interface make callbacks into a data
store process' private memory?

Something like that is possible, although callbacks are used for
something different than what your describe. Standard C doesn't support
multiple processes, so this is off-topic in this newsgroup.

You need to check systems that support multiple processes. It may also
be possible, in some systems, to allow a single process to write an area
of memory and others to only read.
 
K

Keith Thompson

user923005 said:
I want to make data stored in-memory (not disk) available to several
processes.
[...]
Try news:comp.programming.threads

I suspect that's not the right place to ask. The OP asked about
processes, not threads; in many system, those are quite different
things.

It's probably better to ask in a newsgroup that deals with whatever
operating system the OP is using. At a guess, comp.unix.programmer
seems likely.
 
C

CBFalconer

Keith said:
user923005 said:
Sune said:
I want to make data stored in-memory (not disk) available to
several processes.
[...]
Try news:comp.programming.threads

I suspect that's not the right place to ask. The OP asked about
processes, not threads; in many system, those are quite different
things.

To share memory you either need threads or some other arrangement
to specifically share a memory block. Threads are probably the
easiest initial mechanism.
 
K

Keith Thompson

CBFalconer said:
Keith said:
user923005 said:
I want to make data stored in-memory (not disk) available to
several processes.
[...]
Try news:comp.programming.threads

I suspect that's not the right place to ask. The OP asked about
processes, not threads; in many system, those are quite different
things.

To share memory you either need threads or some other arrangement
to specifically share a memory block. Threads are probably the
easiest initial mechanism.

<OT>
How exactly do threads help you share memory between proceses?

Unix-like systems typically have mechanisms to share memory between
processes; these mechanisms are independent of threads, which exist
within a single process.
</OT>
 
C

CBFalconer

Keith said:
.... snip ...


<OT>
How exactly do threads help you share memory between proceses?

Unix-like systems typically have mechanisms to share memory between
processes; these mechanisms are independent of threads, which exist
within a single process.
</OT>

Because, at least in my mind, threads of a process all operate in
the same memory space, and all we have to do is control access.
Processes go to some trouble to keep the memory isolated.
 
K

Keith Thompson

CBFalconer said:
Because, at least in my mind, threads of a process all operate in
the same memory space, and all we have to do is control access.
Processes go to some trouble to keep the memory isolated.

Yes, and the OP specifically asked about sharing memory among
*processes*. Maybe threads are a better solution to his underlying
problem, but you should at least mention that you're suggesting an
alternative rather than answering his actual question.
 
U

user923005

Yes, and the OP specifically asked about sharing memory among
*processes*. Maybe threads are a better solution to his underlying
problem, but you should at least mention that you're suggesting an
alternative rather than answering his actual question.

Sharing memory between processes is actually a lot easier than sharing
memory among threads. The same ideas apply except that threads also
share the memory within the process.

I suspect that if the O.P. just wants to know how to create, use, and
destroy a shared memory segment then he will have to look at the
documentation for the operating system that he is using or use an
abstraction layer like ACE.

The guy who wrote FastDB has some C shared memory libraries that make
Windows boxes look like POSIX machines for shared memory calls. Of
course, that won't help much if the O.P. is not on Windows or POSIX
type operating systems.
His site is:
http://www.garret.ru/~knizhnik/
but I can't seem to connect right now.
 
S

Stephen Sprunk

Keith Thompson said:
<OT>
How exactly do threads help you share memory between
proceses?

Unix-like systems typically have mechanisms to share memory
between processes; these mechanisms are independent of
threads, which exist within a single process.

Threads are sometimes referred to as lightweight processes.

S
 
C

CBFalconer

Stephen said:
Threads are sometimes referred to as lightweight processes.

I believe Linux specifically creates processes and defeats the
memory isolation provisions in creating threads.
 
S

Stephen Sprunk

CBFalconer said:
I believe Linux specifically creates processes and defeats the
memory isolation provisions in creating threads.

Linux now has a single spawn() syscall, which takes various options; some of
them result in a separation of memory space (i.e. processes), and some don't
(i.e. threads). All the kernel cares about is scheduling threads; which
ones occupy the same memory space as others is a minor detail.

S
 
F

Flash Gordon

Stephen Sprunk wrote, On 07/07/07 09:10:
<snip>

All of which is off topic. Both of you, if you want to discus it
further, take it to email or a group where it is topical please.
 
C

Chris Thomasson

[...]
Sharing memory between processes is actually a lot easier than sharing
memory among threads.

[...]

Really? Maintaining consentient and coherent state between multi-processes
synchronization is more difficult and cumbersome than doing the same for
multi-threads. Why would you need to use a robust mutex for a purely
threaded design? Designing reliable _and_ correct robust synchronization
objects are more _complex_ than usual!
 
C

Chris Thomasson

Sune said:
Hi all,

I want to make data stored in-memory (not disk) available to several
processes. My concern is that poorly written C applications with
dangling pointers may(will) damage the data in this memory segment if
it is open to all, i.e. shared memory mapped into all processes memory
area.
[...]

http://groups.google.com/group/comp.programming.threads/msg/dc86197f1882dc56

http://groups.google.com/group/comp.programming.threads/browse_frm/thread/e445e6fe981788e7

Read both of those and follow all links...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top