There's no difference between doing a fork() and simply starting N copies of the program, from a practical perspective. You can _still_ have shared memory. That's what the system V shared memory library is all about, you can create shared memory objects that any process can map into its virtual address space. Ditto for the other approach using mmap(). Otherwise, on modern Unix systems, if you start two instances of the program (assuming it is the exact same program, as in having the same i-node for both instances) they will even share memory pages for instructions and such, just like the fork() processes will.Carey wrote:Actually there, although it's only a little removed.bob wrote:Just to clarify, there isn't any "something else".Carey wrote:Okay, I just got through running some tests.
I am using the latest MingW, which is v3.x. As Bo Persson points out, that may be a good part of my problem. (But since MingW hasn't officially released a version based on a current version of GNU C 4, and probably wont until the next decade, there isn't a lot I am willing to do. I don't like running alpha's or private builds.)
I tested my program with GCC v3, OpenWatcom and MSVC 2008 Express.
I did the 'data in class' vs. 'data outside of class'. I didn't bother testing the plain C version because that should be comparable to 'data outside of class'.
Needless to say, OpenWatcom was the slowest. Dead dog slow. Almost twice as long as MSVC. Probably the only other 'professional' compiler that would be slower would probably be Borland's current free Turbo C++.
Anyway, OpenWatcom had a performance penalty of about about 8%.
I tried a couple versions of MingW with a few different switches. (I didn't try all the switches it offers. Just what the CodeBlocks IDE offers.) The performance penalty was 9%.
I tried MSVC 2008 Express. The performance penalty was 3%.
(I don't know if the free student version of MSVC pro tools would do any better. I'm not a college student and unfortunately, I don't know any to ask if they'd get me a free copy from Microsoft.)
So it looks like there is indeed a non-trivial performance penalty when you put the data into a C++ class.
Much of that can be optimized away by using a state-of-the-art compiler with significant optimization abilities.
Anything with just 'average' or 'good' optimization abilities will be at a serious disadvantage with C++ code.
So I guess most of this thread has been taken care of.... If I want to do multi-core programming, I'm going to have to stay with MSVC. In which case it doesn't matter too much whether it's threads or processes or something else.
Normal 'process' programm just forks and shares some read-only data and them communicates through shared memory, while sharing the trans table.
The 'something else' is to go all the way and use entirely seperate programs communicationg though some channel (pipes, or LAN, or whatever you want). No shared memory, etc.
Each engine can be running on a different core or even a different processor.
It solves all the shared memory bugs & issues, while increasing the communication complexity.
Not much removed, but there are enough differences in what can be done that it's worth calling it 'something else'.
Threads are on the left, common fork()ing processes in the middle, and entirely seperate programs on the right.
That was what I meant by "there is no other approach". Threads share _everything_, the other approach is to just share what you explicitly want to share...