child thread question

Q

QQ

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!
 
K

Keith Thompson

QQ said:
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?

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

Try comp.programming.threads.
 
W

Walter Roberson

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?

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.
 

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

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top