child thread question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • QQ

    #1

    child thread question

    Hi I am writing a multithreads program.
    I have a variable in the main thread,
    can I use it at the child thread?
    For example I have a count in main,
    when the count reaches 10, I will execute some command at the child
    is it OK?

    Thanks a lot!

  • Keith Thompson

    #2
    Re: child thread question

    "QQ" <junciu@yahoo.c om> writes:[color=blue]
    > Hi I am writing a multithreads program.
    > I have a variable in the main thread,
    > can I use it at the child thread?
    > For example I have a count in main,
    > when the count reaches 10, I will execute some command at the child
    > is it OK?[/color]

    We don't know. Standard C doesn't have threads.

    Try comp.programmin g.threads.

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.

    Comment

    • Walter Roberson

      #3
      Re: child thread question

      In article <1115842971.974 474.275590@z14g 2000cwz.googleg roups.com>,
      QQ <junciu@yahoo.c om> wrote:[color=blue]
      >Hi I am writing a multithreads program.
      >I have a variable in the main thread,
      >can I use it at the child thread?
      >For example I have a count in main,
      >when the count reaches 10, I will execute some command at the child
      >is it OK?[/color]

      Maybe, maybe not. You did not happen to mention which threading
      package you are using: there are different ones with different rules.

      Not much about threading is generally considered appropriate in
      comp.lang.c though, as clc deals mostly with ANSI/ISO standard C,
      and threading is not part of those standards per se.


      If you are using POSIX threads then you may wish to look at
      condition variables -- though there are other ways such as
      semaphores, write locks, and mutexes. For the condition you describe,
      a semaphore would perhaps be the most natural, but I can't tell
      at the moment whether it is part of POSIX threads or a local extension
      on the man page I am examining. And as to how you would proceed under
      Windows or other versions of threading... well, best ask these questions
      in a newsgroup more specific for your OS.
      --
      I was very young in those days, but I was also rather dim.
      -- Christopher Priest

      Comment

      Working...