cl***@yahoo.de wrote:
i have just a little question:
guess i have a class with a static function [lets say CA::static()]
and i have different threads running. do i have to expect the problem
that 2 treads try to acces CA::static() at the same time or does the
processor always make shure that one of them has to wait till the
other finishes? or may it be that a static func can be executed twice
at the same time? or should i implement something like:
bool CA::fInUse = false;
CA::static() {
while (fInUse) ;
fInUse = true;
// do something //
fInUse = false;
}
First of all, let me mention that threading is not part of C++ language
and because of that discussions on threads are generally off-topic here.
Try comp.programming.threads. But here is a couple of thoughts:
If you have to ask, it's time for you to study those things seriously.
Threading cannot be explained in a single newsgroup posting, please
refer to 'comp.programming.threads' and their recommendation of books
and start systematic learning of it.
Functions can be called from different threads, it's the *data* that
should concern you. Access to data often has to be paid the most
attention to. To simplify it: two threads should not attempt to write
to the same memory area "at the same time". Nor one should read while
the other one is writing. Doing those things causes trouble.
How to protect things from being screwed up in a multithreaded program,
you need to learn. It can be done from books. It can be done on the
'Net It can be "picked up" by reading documentation and looking at
somebody else's code, but that usually leads to forming serious
misconceptions which are difficult (though necessary) to un-learn later.
So, make THE RIGHT CHOICE(tm).
Good luck!
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask