473,763 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C, signal, variable STOR and reentrancy

All:

Quick question regarding reentrancy and C99 signals. If we have a C
statement such as:

variable = 123456;

And the resulting compiled machine code for a particular fake platform
is to load the constant into a register, and then use **TWO** STORE
machine instructions to store the variable back to memory, so that it
looks like:

LOAD 123456, REG
STOR REG_UPPERHALF, ADDR1
STOR REG_LOWERHALF, ADDR2

Is it possible for a signal to be delivered between the STOR's? If so,
what prevents general lvalue modifications from being (for lack of a
better word) non reentrant (ie... the signal handler can modify
REG_LOWERHALF, and when it returns, the lower half of the STOR will be
incorrect)? Are lvalue modifications under C considered atomic?
Please provide a reference into the standard. Thanks so much!

Nov 17 '06 #1
6 1443
Please excuse this question. I answered it myself. C99 7.14.2. -
sig_atomic_t. Many thanks for this wonderful group.

-Charlie

charles_g...@me rck.com wrote:
All:

Quick question regarding reentrancy and C99 signals. If we have a C
statement such as:

variable = 123456;

And the resulting compiled machine code for a particular fake platform
is to load the constant into a register, and then use **TWO** STORE
machine instructions to store the variable back to memory, so that it
looks like:

LOAD 123456, REG
STOR REG_UPPERHALF, ADDR1
STOR REG_LOWERHALF, ADDR2

Is it possible for a signal to be delivered between the STOR's? If so,
what prevents general lvalue modifications from being (for lack of a
better word) non reentrant (ie... the signal handler can modify
REG_LOWERHALF, and when it returns, the lower half of the STOR will be
incorrect)? Are lvalue modifications under C considered atomic?
Please provide a reference into the standard. Thanks so much!
Nov 17 '06 #2
ch**********@me rck.com said:
All:

Quick question regarding reentrancy and C99 signals. If we have a C
statement such as:

variable = 123456;

And the resulting compiled machine code for a particular fake platform
is to load the constant into a register, and then use **TWO** STORE
machine instructions to store the variable back to memory, so that it
looks like:

LOAD 123456, REG
STOR REG_UPPERHALF, ADDR1
STOR REG_LOWERHALF, ADDR2

Is it possible for a signal to be delivered between the STOR's?
Yes.
If so,
what prevents general lvalue modifications from being (for lack of a
better word) non reentrant (ie... the signal handler can modify
REG_LOWERHALF, and when it returns, the lower half of the STOR will be
incorrect)?
Nothing, unless variable is of type sig_atomic_t.
Are lvalue modifications under C considered atomic?
For objects of type sig_atomic_t, yes. Otherwise, no.
Please provide a reference into the standard. Thanks so much!
Just search the Standard for sig_atomic_t - in my C89 draft, it's section
4.7, and in C99 it's 7.14.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 17 '06 #3
Thanks so much Richard. I actually stumbled across that at the last
moment, my deepest apologies. I have a followup as well. Is there any
guarentee that when an lvalue is accessed for a read, that the
resultant machine code will be loads and no stores. I ask as I am
trying to verify the validity of statements regarding threads
(specifically pthreads, and I understand outside the scope of this
newsgroup) that they can access global shared memory without mutex or
locks as long as the accesses are only reads, since the threads
maintain thread local stacks and registers. However, if in some
strange implementation, everytime you read a variables value, the
resultant machine code also contained some STOR to shared memory (I
don't know why that'd ever be the case, but regardless), this would not
necessarilly be true. I know that sounds very far fetched, but I'm
more or less trying to wrap my head around the theory of it all, and
see what truly is *guarenteed* in the standards. Thanks so much to
everyone in the group and thanks again Richard!


Richard Heathfield wrote:
ch**********@me rck.com said:
All:

Quick question regarding reentrancy and C99 signals. If we have a C
statement such as:

variable = 123456;

And the resulting compiled machine code for a particular fake platform
is to load the constant into a register, and then use **TWO** STORE
machine instructions to store the variable back to memory, so that it
looks like:

LOAD 123456, REG
STOR REG_UPPERHALF, ADDR1
STOR REG_LOWERHALF, ADDR2

Is it possible for a signal to be delivered between the STOR's?

Yes.
If so,
what prevents general lvalue modifications from being (for lack of a
better word) non reentrant (ie... the signal handler can modify
REG_LOWERHALF, and when it returns, the lower half of the STOR will be
incorrect)?

Nothing, unless variable is of type sig_atomic_t.
Are lvalue modifications under C considered atomic?

For objects of type sig_atomic_t, yes. Otherwise, no.
Please provide a reference into the standard. Thanks so much!

Just search the Standard for sig_atomic_t - in my C89 draft, it's section
4.7, and in C99 it's 7.14.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 17 '06 #4
ch**********@me rck.com said:
Thanks so much Richard. I actually stumbled across that at the last
moment, my deepest apologies. I have a followup as well. Is there any
guarentee that when an lvalue is accessed for a read, that the
resultant machine code will be loads and no stores.
I am not aware of any such guarantee.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 17 '06 #5
Richard Heathfield wrote:
ch**********@me rck.com said:
>Thanks so much Richard. I actually stumbled across that at the last
moment, my deepest apologies. I have a followup as well. Is there any
guarentee that when an lvalue is accessed for a read, that the
resultant machine code will be loads and no stores.

I am not aware of any such guarantee.
Adding the volatile qualify is likely to help although it does depend on
how the implementation chooses to define an access. In my experience,
when using type sig_atomic_t you normally also want volatile.
--
Flash Gordon
Nov 18 '06 #6
In article <11************ **********@e3g2 000cwe.googlegr oups.com>
<ch**********@m erck.comwrote:
>... I have a followup as well. Is there any
guarentee that when an lvalue is accessed for a read, that the
resultant machine code will be loads and no stores.
Not in general, no.

In general, the "volatile" qualifier is necessary but not sufficient
to obtain such a guarantee. It is up to each implementation to
define an "access" for a volatile-qualified type, so -- at least
in theory -- you simply read your implementation document(s) to
see what it/they say, and use that information to select whatever
it is that is both necessary *and* sufficient. This may include
restricting the base type(s) of the volatile-qualified types:
e.g., perhaps "volatile int" is atomic while "volatile long long"
and/or "volatile double" is not.
>I ask as I am trying to verify the validity of statements
regarding threads (specifically pthreads, and I understand
outside the scope of this newsgroup) that they can access global
shared memory without mutex or locks as long as the accesses are
only reads, since the threads maintain thread local stacks and
registers.
C does not make such a guarantee, but some other, more restrictive
standard could. Suppose (for instance) that the Zorblatt 25 computer
has a problem with *all* memory-read operations, such that every
load is followed by a store in the generated code (because "load"
means "load and clear", because the Zorblatt has actual "core"
memory with its destructive-read system, and no auto-rewrite).
This machine can support ISO C, but not the other, more-restrictive
standard: any valid, strictly conforming C program runs fine on
the Zorblatt 25, but code that uses thread extensions does not.

In general, the more constraints some programming language or
standard makes, the fewer machines it can run on, but the easier
it is to use. If C had less "undefined behavior", we might be
able to say what "i++ * i++" means, but we might not be able
to implement C on every new machine that comes along (or at least,
not efficiently) -- consider VLIW machines, for instance, with
their multiple functional units. (See the Wikipedia entry at
<http://en.wikipedia.or g/wiki/VLIW>.)
>However, if in some
strange implementation, everytime you read a variables value, the
resultant machine code also contained some STOR to shared memory (I
don't know why that'd ever be the case, but regardless) ...
The above example (magnetic core memory) suggests a possible reason.
Reads are performed by writing a value (normally 0) to the location
whose value is to be read. If writing a zero requires *changing*
the state, the magnetic field flips. This flip is tested-for. If
nothing is sensed, the previous value must have been 0; if something
is sensed, the previous value must have been 1. (For more detail,
see <http://en.wikipedia.or g/wiki/Magnetic_core_m emory>.)

Interestingly, conventional DRAM actually has the same problem as
old-style magnetic core memory: reads are destructive, because they
discharge the capacitor at the heart of each DRAM cell. In this
case, however, it is necessary for the chip itself to rewrite the
cell contents, as an entire row (or column, in CAS-before-RAS) is
dumped into the row-wide sense amplifiers. This internal rewrite
is harnessed for DRAM refresh. (I am deliberately skipping over
all kinds of detail; again, there is more in Wikipedia at
<http://en.wikipedia.or g/wiki/DRAM>.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 20 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3906
by: Ahmed Ossman | last post by:
hi, I want to save the return value from the signal() function, what is the type of the variable. i.e. I want to do the following: <variable type?> ret_sig = signal(......); I need it soo much. Thanks, Ahmed Ossman
2
2212
by: lpw | last post by:
I have dilligently reviewed FAQ-lite Section 3.2, "How do I pass a pointer-to-member-function to a signal handler, X event callback, system call that starts a thread/task, etc." The only suggestion on how to deliver a signal to an object is to do it via a global variable and a wrapper function, a technique that is generally a Bad Idea (due to the usage of a global variable). I understand that this ng is dedicated to the discussion of...
11
2974
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
5
2611
by: Sontu | last post by:
Hi all, Consider the following code: #include<signal.h> #include<stdio.h> #include<sys/mman.h> void handler(int sig) {
3
2801
by: XPhaktor | last post by:
In C#, how do I replace using VB local static variable declarations to handle method reentrancy. Note, if you use a class-scope variable instead of a local one, then you run the risk of inadvertently changing the variable's value in another method that is performing the same technique. The Interlocked.Exchange class uses a class-scope class attribute. Reentrancy is not just a problem for user events (e.g., overzealous users...
13
17719
by: vashwath | last post by:
Hi all, In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant. void sigsegenv() { printf("\n\n ********** F D S Message ***********\n\n"); printf("\n\n ********** S E G M E N T A T I O N F A U L T inside F D S ***********\n\n");
8
7571
by: hlinzhou | last post by:
I am interested in digging the include directory of my favorite gcc compiler specialized for windows(yes u get it, I use Dev-C++, but I love c and type commands in the console).But when I find signal.h and try it, I meet some problems.My code is: /*signal-win.c*/ #include <stdio.h> #include <signal.h> #include <windows.h>
18
3919
by: Sven | last post by:
Hi, I found a strange behaviour when using the time() function from time.h. Sometimes when it is called, it does not show the correct time in seconds, but an initial value. This time seem to be the time when the program was started the first time. My platform is a DEC machine with Tru64 onboard. A possible explanation could be, that the time() function is called
1
3140
by: Arya, Manish Kumar | last post by:
Hi, I am new to python. I have written a simple code to upload a file via ftp to remote server ------------- import sys import ftplib host=sys.argv
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9828
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8825
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7370
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.