Jump to content
  • Advertisement
Sign in to follow this  
jumpjumpjump

C++ threading

This topic is 4720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing a simple server that is suppose to have a thread per client so it can communicate directly with them. My problem is, I want to make my code as cross platform as I can. So I need to write a thread class. I am pretty much lost on what to do here. Does anyone have any links on how to make my own threading system for my server?

Share this post


Link to post
Share on other sites
Advertisement
No, not practically. I think that if cross-platform threading was trivial then they wouldn't have bothered putting it into Boost.

Share this post


Link to post
Share on other sites
Quote:
Original post by mattnewport
There's no support for threads in standard C++. If you want cross platform threading you could try boost threads.

I was always thinking that pthreads were cross platform, too. But these boost ones looks good.

Share this post


Link to post
Share on other sites
Threads are (unfortunatly) very platform-specific for C++ code. You can quite happily use Win32 (or whatever) platform-specific code to do your threading, but if you want cross-platform support why not go with something ready written? There are only so many ways to wrap a low-level threading API.

Share this post


Link to post
Share on other sites
Quote:
Original post by jumpjumpjump
I am pretty much lost on what to do here. Does anyone have any links on how to make my own threading system for my server?


Well it will give you one horrible dependency, but you could consider using SDL's threads. Here is some code that someone made that improved upon the system for threads in a client/server environment.

Share this post


Link to post
Share on other sites
Quote:
Original post by jumpjumpjump
I've been reading around this forum and have heard something about this http://www.ecst.csuchico.edu/~beej/guide/net/html/advanced.html#select

Does WinSock 2.2 have something like that?

Yes, you can use select() with blocking sockets on Windows. Sockets on Windows behave a bit differently from POSIX sockets but the differences are fairly minor and it's fairly easy to write cross platform socket code. If you can do everything you need with select() you might not need portable threads.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!