LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to implement multithreading in Socket ??? (https://www.linuxquestions.org/questions/programming-9/how-to-implement-multithreading-in-socket-166585/)

ponka128 04-05-2004 05:18 PM

How to implement multithreading in Socket ???
 
Hi,
I have a problem with socket programming , I have implemented multiple clients single server through Select System call and it is working fine. i am trying to implement Multithreading in that multiclient single server Code But i m not succeeded ,please help .
How to implement multithreading in multiclient single server code.( Select System call )
Imran

Mara 04-06-2004 05:26 PM

A new thread should be started after every accept (for every new connection). The thread handles user data what main function is still listening for new clients. Is it what you mean?

r4nd0mz 05-22-2004 10:16 PM

yea, thats probably what he means. I know how to do this for windows, but the CreateThread() function doesn't work on my linux. I'm trying to program a server just like ponka128, but I have no clue how to initiate a thread, using something like the windows' function: CreateThread!! any help would be cool, but i'll keep diggin.. :study:

paulsm4 05-23-2004 12:32 AM

You want pthreads
 
Hi -

You want to use "Posix threads" (aka "pthreads"). It provides both thread APIs, as well as a small - but rich - set of synchronization primitives.

You can probably find some good pthread tutorials and FAQs with a simple Google search. My favorite book on the subject (just a chapter, actually!) is "Unix Network Programming, Volume 1", by Richard Stevens.

You should have no problem - if you understand multithreading (e.g. from Windows), you should find pthreads very easy.

'Hope that helps .. PSM

Mara 05-23-2004 05:59 AM

To create a thread you use pthread_create. There's a man page for it with links to other important POSIX threads functions.

paulsm4 05-23-2004 10:07 AM

You can also do a Google search on "pthreads tutorials". Here's one good example:

http://www.yolinux.com/TUTORIALS/Lin...ixThreads.html


All times are GMT -5. The time now is 04:12 AM.