Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

multithreading in C++

Name: Ekce 2006-02-04 5:36

I know I've been making a lot of threads here lately, but I'm hoping this is the last one. Is there a simple way to multithread in C++? Is there a function which will split the code between threads? or would I have to switch language to do that? I'm using a pentium4 (if it helps).

Name: Anonymous 2006-02-04 6:12

Multithreading is never simple, just varying degrees of hard. I'd use pthreads since that is what I learned from C, but there should be other multithreading libraries out for C++ if you google it.

Name: Anonymous 2006-02-04 6:21

man fork

Name: Anonymous 2006-02-04 6:42

Name: Ekce 2006-02-04 6:53

Wow, you guys are fast thanks for the reply's, I don't have time to research them tonight, but I will tomorrow morning(it's 5:00am here).

Name: Anonymous 2006-02-04 12:08

Some program designs may be easier to formulate using a multithreaded approach. After all, the real world is asynchronous!

can someone give an example of this? seriously i've never written a program and thought "gee it would be better if something else was happening at the same time as this code instead of right before or after"

Name: Anonymous 2006-02-04 12:50 (sage)

>>6
You know when you are looking at child porn and masturbating at the same time? That is an example of real-world multithreading. Looking at the porn first and then masturbating is not as effective.

Name: Anonymous 2006-02-04 13:23

>>1
As >>2 said, it's never simple because of shared data concurrency and race conditions. You'll soon discover the kind of crap you have to come up with if you want several threads to modify shared data, or read non-elemental data/dependent data at the same time. And you want to share data, otherwise you don't want threads.

Of course, you can do multithreading in C++. There's a way to make a function run in a new thread (and anything it calls will be executed in this new thread), this is simple. This is all that's simple. Then you need to learn about mutexes and semaphores.

You can search Win32 for CreateThread, CreateMutex, and their respective family of functions, and you can learn pthreads, but the best you can do is to use libSDL. It provides cross-platform, simple threading support which means this is the same for any OS and platform you work, be it Windows or Linux, PCs or Macs, and it works in C and C++. SDL's semaphores are also simpler than pthread's.

>>3
Fail, go back to 20 years ago Unix man

>>6
Some program designs may be easier to formulate using a multithreaded approach. After all, the real world is asynchronous!
The real world is also messy as hell.

An example of an inherently multithreaded task is a server.

>>7
ROFL, wins the thread

Name: Anonymous 2006-02-04 13:41

>>6

You've never really written much in the way of sophisticated software, then, have you?

>>1

It's interesting to note that, while currently C++ has no concept of concurrency and you must use system-specific APIs for your multi-threading needs, C++ 0x (the next standard, currently on target for acceptance in 2009) will, in fact, have concurrency-related primitives. 

Herb Sutter, chair of the C++ standards committee (iirc) is currently championing some new language features that he's currently referring to as "Concur".  He'll be presenting it along with Stroustrup at a special seminar in a conference in Santa Clara later this year (http://www.gotw.ca/sands2.htm).  If you happen to have IE available, you can also check out a PDC presentation Sutter gave on the topic linked from http://www.gotw.ca/.

>>3
If I remember my schooling correctly, fork() is a process thing, not a thread thing.

Name: Mr. Welcome 2007-10-03 13:12

(⌒D⌒) Hello. I am "Mr. Welcome to the past bitch fucking bump". I do believe this is a thread from the past in need of a fucking bump, so I would like to fucking bump it. That is why my name is "Mr. Welcome to the past bitch fucking bump".

Name: Anonymous 2007-10-03 13:21

>>7
It is, if you do it fast enough.

Name: Anonymous 2007-10-03 13:57

>>3 is old Unix bearded man

Name: Anonymous 2007-10-03 15:52

Sepples.

Name: Anonymous 2011-02-02 23:23


Don't change these.
Name: Email:
Entire Thread Thread List