Are the functions "time" and "scandir" thread-safe?

Discussion in 'C Programming' started by rnn98@yahoo.com, Dec 3, 2003.

  1. Guest

    hi,
    my multithread application, running under solaris box, is crashing
    eventually.
    I tried to spot and substitute functions not "thread safe", but I
    guess my search wasn't good enough. I have put localtime_r and
    asctime_r where I was using localtime and asctime. But I didn't find
    any correspondent _r function to "time".Also, I found that "readdir"
    is not thread safe. But what about "scandir"?
    Thanks for any help
     
    , Dec 3, 2003
    #1
    1. Advertising

  2. () wrote in
    news::

    > my multithread application, running under solaris box, is crashing
    > eventually.
    > I tried to spot and substitute functions not "thread safe",


    But C doesn't support threading.

    > any correspondent _r function to "time".Also, I found that "readdir"
    > is not thread safe. But what about "scandir"?


    I've never seen these functions in C, are you sure you don't need some
    other newsgroup that would know about these functions?

    --
    - Mark ->
    --
     
    Mark A. Odell, Dec 3, 2003
    #2
    1. Advertising

  3. Guest

    "Mark A. Odell" <> wrote in message news:<Xns94468FE05D9F4CopyrightMarkOdell@130.133.1.4>...
    > () wrote in
    > news::
    >
    > > my multithread application, running under solaris box, is crashing
    > > eventually.
    > > I tried to spot and substitute functions not "thread safe",

    >
    > But C doesn't support threading.
    >


    #include <pthread.h> and link with pthread lib (-lpthread)
     
    , Dec 4, 2003
    #3
  4. () wrote in
    news::

    >> > my multithread application, running under solaris box, is crashing
    >> > eventually.
    >> > I tried to spot and substitute functions not "thread safe",

    >>
    >> But C doesn't support threading.
    >>

    >
    > #include <pthread.h> and link with pthread lib (-lpthread)


    That's not an ISO C header though, is it? No, it is not.

    --
    - Mark ->
    --
     
    Mark A. Odell, Dec 4, 2003
    #4
  5. Though I am probably breaking many "laws" of this newsgroup, I'll answer his
    question. Because ISO C doesn't enforce thread safety, your question will
    boil
    down to your version of the compiler. In most cases, the time function is
    not
    thread safe.

    If you beleive that these functions are not thread safe, whatever thread
    support
    libraries you are using will have mechanisms to force thread safety on these
    functions.
    What you will need to do is the following:

    1. Create a shared lock on every call to the function in question.
    2. Call the function.
    3. Immediately copy the data returned from function to another set (Do not
    just create
    pointer to it, or worse copy the returned pointer).
    4. release the lock.

    Better yet, create some functions to do the above. This "may" help you
    figure out if the
    function is thread safe or not. Though not the quickest answer, not the
    fastest, nor the least time consuming,
    it is however a better answer than being berated for asking a non ISO
    question in a newsgroup
    whose name is comp.lang.c. It would be nice if the name were changed to
    reflect what it is:
    comp.lang.c.ISO.||.flame. :)

    Michael Steve

    "Mark A. Odell" <> wrote in message
    news:Xns9447A93AE6132CopyrightMarkOdell@130.133.1.4...
    > () wrote in
    > news::
    >
    > >> > my multithread application, running under solaris box, is crashing
    > >> > eventually.
    > >> > I tried to spot and substitute functions not "thread safe",
    > >>
    > >> But C doesn't support threading.
    > >>

    > >
    > > #include <pthread.h> and link with pthread lib (-lpthread)

    >
    > That's not an ISO C header though, is it? No, it is not.
    >
    > --
    > - Mark ->
    > --
     
    Michael Steve, Dec 5, 2003
    #5
  6. Michael Steve wrote:
    > Though I am probably breaking many "laws" of this newsgroup,


    Not to mention a few that apply to all of Usenet. Such as "Don't
    top-post!". Also, your formatting is all screwy. Are you inserting your
    own newlines? Because if so, you are placing them poorly and and your
    lines are wrapping anyway, leaving short 1 or 2 word lines.

    Besides that, there are good reasons to observe the topicality rules.
    Please avoid posting off-topic messages in the future.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Dec 5, 2003
    #6
  7. Alan Balmer Guest

    On Fri, 05 Dec 2003 00:49:26 GMT, "Michael Steve"
    <> wrote:

    >Though I am probably breaking many "laws" of this newsgroup, I'll answer his
    >question.


    Why? Do you have a personal reason to dislike the other contributors
    to this group? Direct the OP to a suitable newsgroup, where he will
    surely get a better variety of answers, and where your own answer can
    be read, verified, and commented on by people who might know more than
    you.

    --
    Al Balmer
    Balmer Consulting
     
    Alan Balmer, Dec 5, 2003
    #7
  8. "Michael Steve" <> wrote in
    news:qCQzb.19725$ on Thu 04 Dec 2003
    05:49:26p:

    > Though I am probably breaking many "laws" of this newsgroup, I'll
    > answer his question.


    Incorrectly, I might add.
     
    August Derleth, Dec 7, 2003
    #8
  9. Fao, Sean Guest

    Michael Steve wrote:

    > Though I am probably breaking many "laws" of this newsgroup, I'll answer his
    > question.


    At one time, I hated comp.lang.c because so many were against off-topic
    posts. Despite my disagreeing point-of-view, I continued to read the
    messages from this group in hopes of making a better C programmer out of
    me. After my C class was over for the semester, I wandered over to an
    old Visual Basic newsgroup I once followed, looking to see if any of the
    old crew was still around. What I saw shocked me. Messages about Word,
    Excel, web development, ADO, etc., etc., etc., plagued the newsgroup. I
    estimated for every one on-topic message, there were at least nine
    others, which were not. In addition, the same questions were commonly
    asked three or four times a day. The number of posts became
    overwhelming for people to keep up with. As a result, bad advice was
    common place and corrections were rarely made.

    Despite the off-topicality and repetitive nature of the messages, no one
    seemed to care. Posts were answered and people seemed happy. It was
    then that I gained a high level of respect for the people of CLC.
    Although seemingly cruel at times, comp.lang.c was by far, the most
    professional and informative of all newsgroups I frequently visited.
    Messages were clear and quick to the point. Off-topic messages were
    redirected to newsgroups possibly containing members more educated in
    the topic then anybody here. Furthermore, keeping the amount of noise
    down to a low has by far improved my and many others ability to track
    down important messages using Google. Above all, if bad or incomplete
    advice was given, the people of this newsgroup could be trusted on for
    making the necessary corrections.

    Has comp.lang.c made a better C programmer out of me? I hope so. If
    you absolutely must answer an off-topic message, at least send it in an
    email. I personally prefer the redirection for reasons of verification.
    I would really hate to see comp.lang.c turn into another newsgroup run
    by a bunch of kids. Please don't ruin it for the rest of us by
    responding to off-topic posts the way you did.

    Sean
     
    Fao, Sean, Dec 8, 2003
    #9
  10. () wrote in message news:<>...
    > "Mark A. Odell" <> wrote in message news:<Xns94468FE05D9F4CopyrightMarkOdell@130.133.1.4>...
    > > () wrote in
    > > news::
    > >
    > > > my multithread application, running under solaris box, is crashing
    > > > eventually.
    > > > I tried to spot and substitute functions not "thread safe",

    > >
    > > But C doesn't support threading.

    >
    > #include <pthread.h> and link with pthread lib (-lpthread)


    Mark was hinting to you that your message is off-topic for
    comp.lang.c, since it talks about libraries and functionality
    that are not part of C as such. A good rule of thumb (though
    not invariably true) is that if you need to mention a particular
    implementation for your question to make sense, then it's
    off-topic.

    Since you're asking about programming on Solaris, I suggest
    comp.unix.programmer or comp.unix.solaris.
     
    J. J. Farrell, Dec 8, 2003
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabriel Rossetti
    Replies:
    0
    Views:
    1,329
    Gabriel Rossetti
    Aug 29, 2008
  2. Replies:
    3
    Views:
    1,547
  3. Windows equivalent of scandir( )

    , Nov 30, 2009, in forum: C Programming
    Replies:
    2
    Views:
    1,956
    techgeeknet
    Feb 28, 2013
  4. Sascha Wüstemann
    Replies:
    4
    Views:
    1,067
    Ike Naar
    Aug 3, 2011
  5. John Nagle
    Replies:
    5
    Views:
    475
    John Nagle
    Mar 12, 2012
Loading...

Share This Page