Is stat function thread safe ?

S

satish.burnwal

Can anyone help me: I want to know if stat function call - used to
query file attributes - is thread safe or not. Appreciate your
response.
 
K

Keith Thompson

Can anyone help me: I want to know if stat function call - used to
query file attributes - is thread safe or not. Appreciate your
response.

stat is not a standard C function. Try asking in comp.unix.programmer.
 
U

user923005

Can anyone help me: I want to know if stat function call - used to
query file attributes - is thread safe or not. Appreciate your
response.

It's up to your compiler vendor.
Typically, if your compiler offers threading, either the functions
available are thread safe, or there is a thread safe variant.
I guess that your compiler's documentation or a newsgroup dedicated to
your compiler is the best bet.
 
J

James Kuyper

Mine is redhat linux but when I see the docs at www.redhat.com/docs, I
do not see any doc on stat call. Any other place I can find the doc ?

If you're using redhat linux, then a simple 'man stat' at the command
line will give you all the help you need.
 
A

Antoninus Twink

It need not be. That's why some implementations have a separate
stat_r() version of the call.

On historical implementations it might not be, but modern systems that
implement (a reasonable chunk of) the SUS will provide a threadsafe
stat() out of the box - cf.
I don't recommend asking questions in comp.unix.programmer. Plenty of
people here who don't bother reading comp.unix.programmer anymore will
be happy to assist you if you post your questions here.

Sound advice.
When deciding whom to listen to, take into account who helps you and
who doesn't.

Exactly...
 
C

CBFalconer

James said:
If you're using redhat linux, then a simple 'man stat' at the command
line will give you all the help you need.

Please don't reply to off-topic queries, apart from redirecting the
questioner to an appropriate newsgroup.
 
K

Keith Thompson

CBFalconer said:
Please don't reply to off-topic queries, apart from redirecting the
questioner to an appropriate newsgroup.

Why is redirecting the questioner to an appropriate source of
information other than a newsgroup inappropriate? Either posting to
comp.unix.programmer (as I suggested quite a while before you did) or
typing "man stat" should answer the OP's question.
 
B

Ben Bacarisse

Keith Thompson said:
Why is redirecting the questioner to an appropriate source of
information other than a newsgroup inappropriate? Either posting to
comp.unix.programmer (as I suggested quite a while before you did) or
typing "man stat" should answer the OP's question.

In general I agree, but this case illustrates the problem of off-topic
advice. man stat will probably tell the OP about the stat function,
since they at the stage of not yet knowing about "man" they are
unlikely to know the solution (man 3 stat) or how to find that
solution (man man).
 
R

Richard

CBFalconer said:
Please don't reply to off-topic queries, apart from redirecting the
questioner to an appropriate newsgroup.

Please stop trying to net nanny people. His help was well meant and
almost certainly helped the OP and was related to the C programming
usage in the real world which is what this group is here to discuss and
aid people in.
 
K

Kenny McCormack

stat is not a standard C function. Try asking in comp.unix.programmer.

Looks like you beat me to the punch in the:

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

sweepstakes. Next time, I'll just have to try harder and be quicker.
 
F

Flash Gordon

Richard wrote:

He wishes to use it from C therefore it is totally on topic since
calling such functions is indeed a function of C and catered for in the
standard.

So tell me, what is the correct format specifier for ffprintf to print a
byte DDF field as three characters left padded with 0s?

Yes, there really is a function ffprintf callable from C provided by a
library used by multiple companies (of which mine is one) which can do
what I am asking. The library goes by the names of ff, ffdev and fred
depending on who you talk to.
 
W

Wolfgang Draxinger

Richard said:
He wishes to use it from C therefore it is totally on topic
since calling such functions is indeed a function of C and
catered for in the standard.

Unh, the OP wants to know if stat is thread safe. Threads and
their safe use are complete outside the scope of C, so it's
totally offtopic here.

Some people might argue, that parts of the C standard library,
like errno, are thread unsafe. However those people are ignorant
about thread local storage, and that the errno variable can be
linked as thread local and then is thread safe. So from the pure
language point of view that question cannot be answered, since
it largely interacts with parts outside the scope of any
language (linkage, runtime memory allocation flags or setting
memory thread local, mutex or semaphore locking implemented in
the used functions)

At least once can say, that the interface of stat allows for
thread safety, but if it is so is implementation dependent.

Wolfgang Draxinger
 
R

Richard

Wolfgang Draxinger said:
Unh, the OP wants to know if stat is thread safe. Threads and
their safe use are complete outside the scope of C, so it's
totally offtopic here.


Whatever. He got pointed to the right place so he asked in the right
place. If you wish to help please do, otherwise leave it to people who
can and will.
 
A

Antoninus Twink

Threads and their safe use are complete outside the scope of C, so
it's totally offtopic here.

This is complete garbage, of course.

Thousands of people write multithreaded C programs every day. I'll be
doing so myself later on today.

Take your stupid zealotry somewhere where it's wanted.
 
R

Richard

Antoninus Twink said:
This is complete garbage, of course.

Thousands of people write multithreaded C programs every day. I'll be
doing so myself later on today.

Take your stupid zealotry somewhere where it's wanted.

"Indeed".

The Linux kernel is written in C and many good technical things can be
learnt in the context of C from it including how best to handle
multi-threading in C.
 
W

Wolfgang Draxinger

Antoninus said:
This is complete garbage, of course.

I did not state, that one couldn't do multithreaded programming
with C. I just pointed out, that it's anything "threads" is
outside the scope of the language.
Thousands of people write multithreaded C programs every day.
I'll be doing so myself later on today.

Yeah, so do I. Heck, I even promoted multithreading when most
desktops and servers had only a single CPU core.

But the language "C" is agnostic about a concept called "thread".
Threads are a concept introduced by the plattform. You can of
course do threaded programming in C. You can do it in fact with
every programming language, as long it grants you access to the
operating system's thread management interface.

Having locking machanisms at hand is a goodie, but is not
mandatory, as there are ways to implement certain things
lock-free.

http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms
http://erdani.org/publications/cuj-2004-10.pdf
http://erdani.org/publications/cuj-2004-12.pdf

And here some pretty cool application of lock-free:
http://www.research.ibm.com/people/m/michael/pldi-2004.pdf

Some more stuff from the same guy:
http://www.research.ibm.com/people/m/michael/pubs.htm
Take your stupid zealotry somewhere where it's wanted.

If you want to discuss multithread programming, please go into a
NG that focus on those topics. The language C is a difficult
topic already, adding the confusion implied by (close to) just
increases entropy.

Wolfgang Draxinger
 
R

Richard

Wolfgang Draxinger said:
I did not state, that one couldn't do multithreaded programming
with C. I just pointed out, that it's anything "threads" is
outside the scope of the language.

So is counting elements in a hash table. But people do it in C every
day.
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,225
Latest member
Top Crypto Podcasts

Latest Threads

Top