[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Threads
Brad Johnson wrote:
> > Really, do you actually *need* them?
>
> No. And I can say with confidance that my little 35k game will
> probably never need them. However, it would be nice to know how to use them.
> After all, when the time comes to add sound, I may decide that a thread is
> the way to go (Having another trick in your bag is always helpful). Plus,
> knowing how to use threads may help me understand what the guys discussing
> sound are talking about :)
Of course, knowing about them is never a bad thing! And you'll get to
experience first hand if they work for you or not. But when it comes to
performance, keep an eye on the fps counter, you might be amazed at what
some "optimizations" actually come out as! And one last thing: the
profiler is your friend. :-) Profile, optimize what *needs* to and leave
the rest alone, you'll thank yourself.
> BTW - What exactly is a semaphore? I've heard of them before, and I gather
> that they're similar to threads, but I know even less about them
This is not a threading mechanism, but a communication one. SysV IPC has
a semaphore system in it, but you can implement one yourself rather
easily. It is simply something like an integer (or maybe a bool, I don't
remember much) variable that is shared between the processes or threads.
The idea is that one process can raise the semaphore (by doing an atomic
increment for example) and the other watch for the semaphore being
raised. For example, when you have one working thread and a main thread,
the working thread might raise a semaphore to tell the main thread it
has finished its work.
--
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi