469,929 Members | 1,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

global variable is shared in shared library

Is it possible to share global variables such that all applications
which use shared libraries can see the changes made to the global
variables by the other applications.

Jul 15 '08 #1
3 9610
an******@gmail.com wrote:
Is it possible to share global variables such that all applications
which use shared libraries can see the changes made to the global
variables by the other applications.
You need shared memory or some other form of interprocess communication.
Pure C cannot do what you want except by overly cumbersome ways or my
making system specific assumptions (example: that the system employs no
memory protection etc.). You will get better answers and ideas if you
ask in a group for you system like comp.unix.programmer for UNIX and
clones and comp.os.ms-windows.programmer.win32 for Windows machines.

Jul 15 '08 #2
>Is it possible to share global variables such that all applications
>which use shared libraries can see the changes made to the global
variables by the other applications.
If you want shared memory segments, look at mmap() or the shm*()
functions. These are, of course, not in the C standard.

It would appear that C does not provide sufficient support for
mutexes to really be able to make use of shared variables in a way
that would not screw up often.

Certainly *automatic* sharing of all global variables (errno, anyone?
How about stdin, stdout, and stderr?) in shared libraries would be
a disaster.

Jul 15 '08 #3

<an******@gmail.comwrote:
Is it possible to share global variables such that all applications
which use shared libraries can see the changes made to the global
variables by the other applications.
A "global" variable in a library function is always "global"
over every function within a thread, and probably always "global"
over all threads in a process; but it's normally not "global"
between processes.

Have you looked into using files? If the library maintains
a log file showing what programs have altered what variables,
programs should be able to read that file to see what changes
have been made.

Perhaps record for each change:

Name of program which made the change.
Time of change.
Old value.
New value.

I think you'd find that the various processes don't actually
"change the global variables", as you phrase it, at all!
I think you'd see that each application has ITS OWN COPY of
each of the library's global variables.

That being the case, files would be a good way to communicate
between processes. Have the library write the changes, then
any program that needs to see a fresh snapshot of what the other
programs have been doing can open the log file in read-only
mode, grab a copy of the contents, and quickly close the file,
freeing it for reading by other programs.

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant
Jul 18 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

88 posts views Thread by Tim Tyler | last post: by
4 posts views Thread by Dan Elliott | last post: by
3 posts views Thread by Jim McGivney | last post: by
41 posts views Thread by Miguel Dias Moura | last post: by
1 post views Thread by nidumolu | last post: by
15 posts views Thread by =?Utf-8?B?UGF0Qg==?= | last post: by
11 posts views Thread by tuom.larsen | last post: by
3 posts views Thread by coderr | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.