[OT] This feels wrong (pthreads question)

Dave Smith dave at thesmithfam.org
Sun Jan 28 20:19:26 MST 2007

Levi Pearson wrote:
> Well, it's cool that you're trying to build a scalable system as a 
> learning project, and I think this is a reasonable sort of project to 
> start with.  I think you're getting a bit ahead of yourself, though, 
> and that you ought to take a couple of steps back and start with 
> something simpler.  If you *really* want to use threads, I would 
> suggest reading about them in a bit more depth before trying another 
> design, because your current one is fundamentally broken.  If you just 
> want to build a scalable system, I suggest avoiding threads altogether 
> and building on top of a select()-based event loop.

Levi wrote everything I wanted to write, but I didn't want to spend the 
time doing it. Thanks Levi!

It is *never* a good idea to create a new thread for each user if 
scalability is a requirement. If you really want to use threads, I would 
propose a pool of worker threads that can service clients on demand. 
It'll bound unchecked resource growth and be good experience for you to 
implement. However, it's going to be a lot more work than a 
select()-based event loop. What I've found as I've designed systems like 
this over the years is that the POSIX and UNIX gurus of yesteryear have 
already thought about all these problems, and have given us a hugely 
robust set of tools that do what you need. select() is one of those tools.

Unfortunately, I'm not familiar with any references that would help you 
with this, other than the scar-filled memories in my own mind. ;) Along 
that line of reasoning, this could be a great opportunity to create some 
scars of your own. At least it's not on someone else's dime. I would 
actually recommend implementing the system as you propose so you can get 
a feel for just how problematic it would be. :)

Good luck! Let us know how it goes and if you need testers.


More information about the PLUG mailing list