unix and threads
Hello,
I haven''t had any experience coding in any *ix environment so I''m helping you linux dudes''ll help me out
Right now i''m writing a server and I''m planning doing some thread work. However, I also want to make it as portable as possible (or as *easily* portable as possible). Does coding threads in linux differ from coding threads in win32? If so, how much of a difference? Is portability an impossibility?
Alright... thanks in advance for any help.
~Queasy.
Jonathan Makqueasy gamesgate 88[email=jon.mak@utoronto.ca]email[/email]
I moved this thread here from General because I''d expect more on-topic responses in here...
After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming
There is a pthreads library for win32 out now, so life just got easyer for you.
pthreads-win32
I haven't used this, but the page looks promising. Under the hood linux threads used to be implemented as lightweight shared memory processes (try man clone()) whereas windows seems to share the stack.
The cygnus compiler usually does a good job of building Linux stuff on windows. sockets to winsock is transparent for example. Unfortuneatly things like .so vs .DLL and in particular using MSVC .DLL's used to cause a fair amount of greif.
A simple server, that spawns a thread for each client, and you don't care when that thread exits shouldn't have any problems. Eventually you are probibly going to start pooling sockets and I think that's handled very differently on each.
clanlib May also be of some use for at least the database type stuff.
Edited by - Grib on August 16, 2000 5:52:41 AM
pthreads-win32
I haven't used this, but the page looks promising. Under the hood linux threads used to be implemented as lightweight shared memory processes (try man clone()) whereas windows seems to share the stack.
The cygnus compiler usually does a good job of building Linux stuff on windows. sockets to winsock is transparent for example. Unfortuneatly things like .so vs .DLL and in particular using MSVC .DLL's used to cause a fair amount of greif.
A simple server, that spawns a thread for each client, and you don't care when that thread exits shouldn't have any problems. Eventually you are probibly going to start pooling sockets and I think that's handled very differently on each.
clanlib May also be of some use for at least the database type stuff.
Edited by - Grib on August 16, 2000 5:52:41 AM
Okay cool, thanks
And sorry Godfree^, I wasn''t paying attention at 5 in the morning (I don''t understand how you guys can!)
~Queasy.
And sorry Godfree^, I wasn''t paying attention at 5 in the morning (I don''t understand how you guys can!)
~Queasy.
Jonathan Makqueasy gamesgate 88[email=jon.mak@utoronto.ca]email[/email]
Okay, sorry to bug you again, but have you come across any good pthreads tutorials? The dL did not include any (I have no idea how to code posix threads).
Thanks again.
Thanks again.
Jonathan Makqueasy gamesgate 88[email=jon.mak@utoronto.ca]email[/email]
you can try the FAQ and a set of example programs from here there are also the man pages (the most important part).
The short answer is that pthreads use a function as the "entry point" for the a thread.
the funcution must be void * foo(void *) i.e. takes a void pointer as a param, and returns a void pointer. You create a new thread with pthread_create() passing it a pointer to a static pthread_t object, a pointer to the attributes, a pointer to the above function and a void pointer to pass to the function. The value returned from foo is the value returned from pthread_join(tid) As usual the greif is not the syntax (though its your usuall "too damm portable for it's own good" syntax IMO) but our friends deadlock and race condition. You may want to look up the select() system call(and whatever windows folks do). When clients constantly send messages, need messages, and interact with one another in non-trivial ways (such as killing one another) you spend so much time in mutexes that the ability to block on a read() without hanging the system begins to look less and less usefull.
Edited by - Grib on August 16, 2000 4:49:48 PM
The short answer is that pthreads use a function as the "entry point" for the a thread.
the funcution must be void * foo(void *) i.e. takes a void pointer as a param, and returns a void pointer. You create a new thread with pthread_create() passing it a pointer to a static pthread_t object, a pointer to the attributes, a pointer to the above function and a void pointer to pass to the function. The value returned from foo is the value returned from pthread_join(tid) As usual the greif is not the syntax (though its your usuall "too damm portable for it's own good" syntax IMO) but our friends deadlock and race condition. You may want to look up the select() system call(and whatever windows folks do). When clients constantly send messages, need messages, and interact with one another in non-trivial ways (such as killing one another) you spend so much time in mutexes that the ability to block on a read() without hanging the system begins to look less and less usefull.
Edited by - Grib on August 16, 2000 4:49:48 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement