[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Context switching woes

Mark Collins wrote:

> > I'd say you should also merge the networking thread, but that's just me.
> > See my signature and this:
> >
> > http://www3.sympatico.ca/pphaneuf/thread.html
> >
> > ;-)
> FUD :-)

I'll let you to your own ideas, it doesn't pay for me to fight them. :-)

The theory is quite straightforward about threads: they are always less
efficient than doing the same thing without thread. Where you gain is
with *apparent* ease of programming (getting short latency without
threads is not obvious, and threads makes it magically easy), but as a
whole, when you take into account all the race conditions and locking
overhead and other such things, single threaded programming is easier,
more efficient and just as good latency-wise once you get the hang of

> > Seems like the scenegraph needs to be protected by a lock. Simple, no?
> > Well, as simple as it gets when you're involving threads...
> It depends. The is a small chance (say, 1 in a billion) that there could be
> a context swicth when the lock check is being done, and 2 subsystems getting
> a lock at the same time.

Locking and unlocking operations provided by the threading library are
atomic, or the library isn't worth crap. In the case of pthread on
Linux, the operations *are* atomic. One and only one thread can EVER get
a lock at a particular given moment. EVER.

> > What do you mean about that lock working on a single processor, but not
> > on a multi-processor system?
> If 2 different threads are running on two different processors, the chance
> of a context switch at the worst possible moment in time increases.

Again, pthread's locks are atomic. They have been designed for that very
purpose, single or multiple processors.

> > "A computer is a state machine. Threads are for people who can't
> > program state machines." -- Alan Cox
> Hmm, I wonder is AC is releated to Tony Cox (head of DirectX development,
> who I'm exchanging a lot of emails with atm)

At the crazy rate people use threads on Win32, I doubt AC would ever
acknowledge such a relation. ;-)

Just ask Alan (is Tony Cox english, because Alan is)...

"And the Answer is... 42." -- Deep Thought

To unsubscribe, e-mail: linuxgames-unsubscribe@sunsite.dk
For additional commands, e-mail: linuxgames-help@sunsite.dk