Is there a way to read a line (a series of characters ending in a
newline) from a file (either by descriptor or stream) atomically,
without buffering additional contents of the file? 11 1989
japhy wrote:
Is there a way to read a line (a series of characters ending in a
newline) from a file (either by descriptor or stream) atomically,
without buffering additional contents of the file?
Within Standard C all you can do is use the setvbuf function and
specify no buffering with _IONBF as one of it's arguments. Despite
this, the operating system may still use disk buffers when doing I/O.
To turn off all buffering is system dependant and you'll have to
examine the facilities your OS provides to do so.
The word atomic is inappropriate in the context in which you've used
it. Even when buffering is disabled, I/O is not guaranteed to be an
atomic operation.
In article <11********************@p10g2000cwp.googlegroups.c om>,
santosh <sa*********@gmail.comwrote:
>japhy wrote:
>Is there a way to read a line (a series of characters ending in a newline) from a file (either by descriptor or stream) atomically, without buffering additional contents of the file?
>The word atomic is inappropriate in the context in which you've used it. Even when buffering is disabled, I/O is not guaranteed to be an atomic operation.
Though if you make the step over to POSIX, writes below a
system-dependant size are promised to be atomic. POSIX needs
this property because it deals with multiple processes (and
multiple threads in later editions) and it would be a real
nuisance to have the output of one write intermixed with the
output of another write.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
Walter Roberson wrote:
In article <11********************@p10g2000cwp.googlegroups.c om>,
santosh <sa*********@gmail.comwrote:
japhy wrote:
Is there a way to read a line (a series of characters ending in a
newline) from a file (either by descriptor or stream) atomically,
without buffering additional contents of the file?
The word atomic is inappropriate in the context in which you've used
it. Even when buffering is disabled, I/O is not guaranteed to be an
atomic operation.
Though if you make the step over to POSIX, writes below a
system-dependant size are promised to be atomic. POSIX needs
this property because it deals with multiple processes (and
multiple threads in later editions) and it would be a real
nuisance to have the output of one write intermixed with the
output of another write.
Yes, thanks, I should probably have mentioned that, but I was thinking
more along the lines of the C standard's assurances with regard to
atomic operations.
santosh wrote:
>
.... snip ...
>
Yes, thanks, I should probably have mentioned that, but I was
thinking more along the lines of the C standard's assurances
with regard to atomic operations.
The C standard runs on a dedicated machine with no processes,
threads, interrupts, etc. and thus has no need of atomic
operations, semaphores, etc.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
CBFalconer said:
santosh wrote:
>>
... snip ...
>> Yes, thanks, I should probably have mentioned that, but I was thinking more along the lines of the C standard's assurances with regard to atomic operations.
The C standard runs on a dedicated machine with no processes,
threads, interrupts, etc. and thus has no need of atomic
operations, semaphores, etc.
Almost true. Even if we ignore the C99 floating point stuff as being
irrelevant here, we still must not forget sig_atomic_t, which is
defined to be "the (possibly volatile-qualified) integer type of an
object that can be accessed as an atomic entity, even in the presence
of asynchronous interrupts".
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www.
"santosh" <sa*********@gmail.comwrote:
# Walter Roberson wrote:
# In article <11********************@p10g2000cwp.googlegroups.c om>,
# santosh <sa*********@gmail.comwrote:
# japhy wrote:
# Is there a way to read a line (a series of characters ending in a
# newline) from a file (either by descriptor or stream) atomically,
# without buffering additional contents of the file?
# >
# The word atomic is inappropriate in the context in which you've used
# it. Even when buffering is disabled, I/O is not guaranteed to be an
# atomic operation.
# >
# Though if you make the step over to POSIX, writes below a
# system-dependant size are promised to be atomic. POSIX needs
# this property because it deals with multiple processes (and
# multiple threads in later editions) and it would be a real
# nuisance to have the output of one write intermixed with the
# output of another write.
#
# Yes, thanks, I should probably have mentioned that, but I was thinking
# more along the lines of the C standard's assurances with regard to
# atomic operations.
#
#
#
--
SM Ryan http://www.rawbw.com/~wyrmwif/
One of the drawbacks of being a martyr is that you have to die.
On Mar 2, 2:31 pm, Richard Heathfield <r...@see.sig.invalidwrote:
Almost true. Even if we ignore the C99 floating point stuff as being
irrelevant here, we still must not forget sig_atomic_t, which is
defined to be "the (possibly volatile-qualified) integer type of an
object that can be accessed as an atomic entity, even in the presence
of asynchronous interrupts".
Just for my own information, does "asynchronous interrupts" include
thread pre-emption? Is this how thread mutexes are implemented? I was
perusing the boost library recently and saw a lot of inline assembly
for mutexes, etc. I presume if sig_atomic_t were thread-safe as well
as signal safe the boost people could have saved a lot of trouble?
Or is that because in something like:
void do_something(void)
{
static sig_atomic_t mx = 0;
start:
if (mx++ == 0) {
/* Wait for mx to be zero */
goto start;
} else {
/* Do some work */
}
}
mx may be atomic, but the test (mx++ == 0) is not guaranteed to be an
atomic operation? (And I presume there's no way to make such a
guarantee in C alone.)
-Bluejack
SM Ryan wrote:
"santosh" <sa*********@gmail.comwrote:
# Walter Roberson wrote:
# In article <11********************@p10g2000cwp.googlegroups.c om>,
# santosh <sa*********@gmail.comwrote:
# japhy wrote:
# Is there a way to read a line (a series of characters ending in a
# newline) from a file (either by descriptor or stream) atomically,
# without buffering additional contents of the file?
# >
# The word atomic is inappropriate in the context in which you've used
# it. Even when buffering is disabled, I/O is not guaranteed to be an
# atomic operation.
# >
# Though if you make the step over to POSIX, writes below a
# system-dependant size are promised to be atomic. POSIX needs
# this property because it deals with multiple processes (and
# multiple threads in later editions) and it would be a real
# nuisance to have the output of one write intermixed with the
# output of another write.
#
# Yes, thanks, I should probably have mentioned that, but I was thinking
# more along the lines of the C standard's assurances with regard to
# atomic operations.
#
#
#
Err, did you have something to say? Your post appears empty of a
reply, (except for the quoted text), but maybe that's a Google Groups
issue?
# Is there a way to read a line (a series of characters ending in a
# newline) from a file (either by descriptor or stream) atomically,
# without buffering additional contents of the file?
Generally once data is transferred from system to program
unless you're explicitly using locks, you lose atomicity.
On systems that transfer chunks of chars and expect the program
to find line structure in that, you aren't going to get
atmoic line reads. Some systems transfer lines; you're more
likely to have atomicity there.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
One of the drawbacks of being a martyr is that you have to die.
"japhy" <ja*******@gmail.comwrote in message
Is there a way to read a line (a series of characters ending in a
newline) from a file (either by descriptor or stream) atomically,
without buffering additional contents of the file?
Not really. The problem is that operating systems are now so complex that it
is difficult to define exactly what we mean by "unbuffered input". For
instance a frequently accessed small file may be memory mapped, completely
transparently to the user.
There are low-level routines provided on most systems that may do what you
want, called "open" insgtead of "fopen" and so forth.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
bluejack said:
On Mar 2, 2:31 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>Almost true. Even if we ignore the C99 floating point stuff as being irrelevant here, we still must not forget sig_atomic_t, which is defined to be "the (possibly volatile-qualified) integer type of an object that can be accessed as an atomic entity, even in the presence of asynchronous interrupts".
Just for my own information, does "asynchronous interrupts" include
thread pre-emption?
Since the Standard doesn't mention threads, it is (alas) impossible to
say within the context of ISO C.
<snip>
mx may be atomic, but the test (mx++ == 0) is not guaranteed to be an
atomic operation?
Correct.
(And I presume there's no way to make such a guarantee in C alone.)
Again, correct.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Moore |
last post by:
I can't find anything which spells this out in the manuals. I guess
that, at some level, the answer is "a single bytecode operation", but
I'm not sure that explains it for me.
This thought was...
|
by: Shayan |
last post by:
Is there a boolean flag that can be set atomically without needing to
wrap it in a mutex? This flag will be checked constantly by multiple
threads so I don't really want to deal with the overhead...
|
by: Seenu |
last post by:
I'm experiencing some puzzling behaviour with some of my UDFs when
declaring them as ATOMIC.. Basically I'm invoking another UDF (which
uses some Java code) in one branch of a CASE statment, and...
|
by: hikums |
last post by:
Begin Atomic
Declare a integer;
Set a=(select count(1) from claims.table1);
if a<>0 then
import into c:\tmptyfile.txt of del replace into claims.table1;
end if;
End!
|
by: Pegboy |
last post by:
What does it mean to make a function atomic?
Something I read on it wasn't very clear, but made me think that I needed to
disable interrupts for that function. Whether that's the case or not,...
|
by: dm |
last post by:
Hi,
I'd like to know if the C standard can guarantee that an assignment to/from
a variable will be atomic, that is will occur in a single indivisible
instruction.
For example, if I have the...
|
by: yogeeswar |
last post by:
Hi All
I wrote SP with number of delete commands in an atomic block.And there is a possibility of deleting records from parent table before child table so I wrote a handler to handle the...
|
by: Michael |
last post by:
Why are functions atomic? (I.e. they are not copied.)
For example, I would like to make a copy of a function so I can change
the default values:
(2, 2)
I would like the following...
|
by: Freedom fighter |
last post by:
Hello,
Is a singleton class the same as an atomic class? I know that a singleton class
can only be instantiated once, but does that concept apply to an atomic class?
Thank you.
|
by: Vishwahere |
last post by:
Hi I am using a query as below:
BEGIN NOT ATOMIC
FOR temp_row AS SELECT pr.REC_TRK_ID,cm.FINC_MTCH_KEY_ID,pr.MED_MTCH_KEY_ID FROM CARDTC.PGM_REQ pr LEFT OUTER JOIN CARDTC.CDB_MTCH cm ON...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |