LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2004, 12:18 AM   #1
kris273
LQ Newbie
 
Registered: Mar 2004
Posts: 19

Rep: Reputation: 0
Pthread VS select


I was curious about the issues and major differences between using Pthread and select to handle multiple clients that will be logged on for an undetermined amount of time.

One way I see is to make detached threads handle every client, each client has a thread devoted to listening to him, and it takes the data, processes it, and returns it on another thread.

the other way is using select, check for input, if so, process and go on.


is there one better or worse than the other? easier or harder? are there any major issues using 2 different threads to communicate with a client on the same socket addr? (is there still an issue if you used multex lock?)


Kris
 
Old 04-06-2004, 05:22 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Both methods are good. Both have advantages and disadvantages.

Threads
* new thread for every client means extra resources for a new client
* functions to handle clients are simplier but
* synchronization required

Select:
* one process, no extra resources for a new client (theory)
* more compilicated function to handle clients, many more cases to take care of
* no synchronization

I must say that multiclient code with select is usually much more compilicated than using threads. Of course, it also depends if you know how to work with threads or not...

There's also a possibility to use both: threads and select in one program. An exaple: WWW server that has new thread for every client (has threads waiting for clients, if there are not enought idle threads new ones are created, if there are too many - they may be killed). Select can be used as a click in the main server function (listening for a new connection). With a limited select time you get a possibility to look if there are enough threads (and create or delete a number of them). Then you can run select again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM
pthread and C++ gt73 Programming 17 11-04-2003 03:01 AM
about pthread c12ayon Programming 6 10-25-2003 04:37 AM
need help about pthread c12ayon Programming 1 10-24-2003 07:47 AM
Pthread rch Programming 1 05-28-2003 02:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration