Re: Architecture design
s0suk3@gmail.co m said:
<snip>
>
Do state machines really have anything to do with parallel processing?
Most people who use threads do so not because they need parallel
processing, but because they think they do. For example, it's commonplace
to see server code with one thread per client, which is a ludicrous misuse
of resources. In a great many cases, threads are simply not a good fit to
the problem. (This says nothing about their portability, of course.)
>>
>>
>>
>That sounds like a factoid to me (like the factoid that "integer
>operations are faster than floating-point operations"). And threads have
>significant *dis*advantages that should not be glossed over.
>
That would sound much more convincing if you stated what disadvantages
those are, and how you can avoid them using processes or state
machines.
If you don't know already, I see little value in continuing this
discussion. But that doesn't mean I'm ducking the question.
The most obvious disadvantage is that threads can compete over object
values. Thread A might try to read the value whilst Thread B is in the
middle of updating that value, for example. So you have to do the whole
semaphore/mutex thing. And you have to be careful to avoid a deadlock,
where Thread A has locked resource C and is waiting for resource D,
whereas Thread B has locked resource D and is waiting for resource C.
Writing thread-safe code is a far from trivial exercise. Writing a state
machine solution is much simpler and generally less bug-prone (at least,
in my experience).
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
s0suk3@gmail.co m said:
On Oct 22, 2:36 am, Richard Heathfield <rjh@see.sig.in validwrote:
>Threads were invented for people who can't
>write state machines (which, incidentally, are far easier to debug).
>write state machines (which, incidentally, are far easier to debug).
Do state machines really have anything to do with parallel processing?
processing, but because they think they do. For example, it's commonplace
to see server code with one thread per client, which is a ludicrous misuse
of resources. In a great many cases, threads are simply not a good fit to
the problem. (This says nothing about their portability, of course.)
In C/C++, you can use frameworks offering a single interface to the
underlying threading environment.
underlying threading environment.
>If you really need to use threads, that's obviously a good way to go.
>But of course most programs would be better off without them.
>But of course most programs would be better off without them.
Either you need them or you don't, of course. I'm just saying that
they have significant advantages over processes in general.
they have significant advantages over processes in general.
>That sounds like a factoid to me (like the factoid that "integer
>operations are faster than floating-point operations"). And threads have
>significant *dis*advantages that should not be glossed over.
That would sound much more convincing if you stated what disadvantages
those are, and how you can avoid them using processes or state
machines.
discussion. But that doesn't mean I'm ducking the question.
The most obvious disadvantage is that threads can compete over object
values. Thread A might try to read the value whilst Thread B is in the
middle of updating that value, for example. So you have to do the whole
semaphore/mutex thing. And you have to be careful to avoid a deadlock,
where Thread A has locked resource C and is waiting for resource D,
whereas Thread B has locked resource D and is waiting for resource C.
Writing thread-safe code is a far from trivial exercise. Writing a state
machine solution is much simpler and generally less bug-prone (at least,
in my experience).
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Comment