Slashdot Mirror


More Effective Use of Shared Memory on Linux

An anonymous reader writes "Making effective use of shared memory in high-level languages such as C++ is not straightforward, but it is possible to overcome the inherent difficulties. This article describes, and includes sample code for, two C++ design patterns that use shared memory on Linux in interesting ways and open the door for more efficient interprocess communication."

13 of 280 comments (clear)

  1. Mod parent redundant by Anonymous Coward · · Score: 1, Insightful

    Yup they released it and it sucks. Although somewhat related, a distributed object cache is a solution to a totally different set of problems. Why mention it here?

  2. Re:C++ has bigger memory issues by ObsessiveMathsFreak · · Score: 5, Insightful

    In fact, forget it; just use an actual OO language instead.

    C++ is an actual Object Oriented language, which is of course half the problem.

    If you mean a pure OO language like Java, in which everything is an object except for primitives and it takes ten classes and wrappers just to read a file, well then C++ isn't exactly an Object Oriented language as such. Perhaps you mean Smalltalk or the like.

    I tell you what though, C++ is still around after all this time. With all the hype surrounding Java, Perl, C#, Python, etc, etc, etc C++ programmers are still there beavering away with the god awful sytax Stroustrup left them with. Even after all the improvments, all the innovation and all the additional research into computer languages, for a hell of a lot of tasks, there is really no real alternative to C++.

    I don't say this as a C++ fanboy, even though I am "somewhat" fond of the language when it is used properly, and not in garbled and unreadable line noise. I say this simply as a statement of fact. There is still no successor to C++.

    I don't want garbage collection so much as I want a cleanup and rationalisation of the syntax. GC would be nice, but forcing more readable code would be even better.

    --
    May the Maths Be with you!
  3. Re:Microsoft code? by Erik+Hensema · · Score: 2, Insightful

    I consider compiling with -Wall good style, which warns you when doing an assignment used as an expression. if ((a = 1)) supresses the warning, assuming the coder knows what he's doing.

    --

    This is your sig. There are thousands more, but this one is yours.

  4. Comments on comments by Tzinger · · Score: 2, Insightful

    Too many people here are willing to make inane useless comments about honest work efforts. If you have a better way, offer it. If you merely want to say something nasty about someone else's work, save it for the coffee house.

    --
    "If all the American people want is security, let them live in prisons." Eisenhower
  5. Re:C++ has bigger memory issues by Anonymous Coward · · Score: 1, Insightful

    That everything is an object in Java except for the primitive types are such a cop out by Sun. Think of all the hacks that result just from that. In Smalltalk, everything is an object even the primitive classes!

    As for why C++ is still being used, it is a more type-safe C at the very least. It is nice to be able to do function overloading and declare variables anywhere. And once one gets past the horrible syntax, amazing things can be done/achieved with C++ templates.

  6. Re:10 fold speed improvement - Dekkers mutex ! fas by Anonymous Coward · · Score: 3, Insightful

    IMHO this algorithm is not a panacea because :

    - It does busy waiting. If one thread holds the 'mutex' for a long time, the other thread will take a lot of CPU for nothing.
    If you really need to take the resource as soon as it is available without giving up the proc, then have a look at "spin locks".

    - It is not very scalable.
    First, you need one version of the algorithm for mono proc one for bi proc, etc. Of course you could put them all in a shared lib and select one at runtime.
    Second, the algo seems to be O(N), N being the number of processors. Therefore the algo slows down when the number of proc increases.

    - And last: it is unclear to me how you pass turn when there are more than 2 procs involved. Does this algorithm work when there is more than 2 processors ?

  7. Re:C++ has bigger memory issues by Viol8 · · Score: 2, Insightful

    "Easy programming languages"

    Excuse me? C may be many things , but easy isn't one of them.
    Ask any beginner. And as for the "security problems" in C , as
    you well know , C was designed as a replacement for assembler.
    It wouldn't have been much use if it didn't give you
    complete flexibility wrt memory access, even if that means
    breaking some of the rules that hand-held high level programmers
    use as a crutch because they're unable to code to the metal.

    "are uninterested in quality and very interested in meeting deadlines"

    If you have a mortgage and a family and your boss threatens you
    with the sack if you keep missing deadlines very few if any
    programmers will take the "moral" stand and get fired. And frankly,
    anyone who puts coding principles above their family is scum IMO.

  8. Re:C++ has bigger memory issues by Viol8 · · Score: 2, Insightful

    Actually I tend to find the opposite. With C everything has to be explicit. ie you want a function called, you have to call it at
    that point in the code. WIth C++ you can use opertor overloading,
    polymorphism, hidden convertions , template specialisation and lots of other stuff which makes the actual code more implicit than C and hides whats actually going on away more. Sure , if you spend some time looking at the code you'll figure it out , but C++ doesn't IMO lend itself to skim reading as much as C does.

  9. Java-trolls are clueless, as usual... by bogolisk · · Score: 2, Insightful

    The article is about shared-mem and synchronization accross process boundary! In Java that would mean: object that are shared between VMs; methods are are serialized across VM boundary.

    --
    Bogus
  10. Re:Microsoft code? by Rakshasa+Taisab · · Score: 2, Insightful

    It has something to do with the direction in which you read the code, from the left to the right. In the former example, you'll have to push "EOF !=" on the mental stack before parsing the meaning of "(c = getc(stdin))".

    I like my manga right to left, my code left to right.

    --
    - These characters were randomly selected.
  11. Preying on the non-comp SCI mods, I see. by Inoshiro · · Score: 4, Insightful

    "How many people know about this? Nobody! I never read about it anywhere. I invented it myself years ago, .."

    Turn to page 55 of your OS design and implementation by Tanenbaum. See where he says, "For a discussion of Dekker's algorithm, see Dijkstra (1965)."? How do you get through a proper comp sci honours degree to the point where you can take a masters and then a PhD without reading Dijkstra?

    How about you crack open that copy of Operating Systems (4th ed) by William Stallings, which has a discussion of concurrency and Dekker's on pages 208-213? How can you get past a 2nd/3rd-year introductory operating systems class without having gone over this topic?

    You are a troll. A troll preying on the fact that most of the moderators here have no idea about computer science, and have not taken a wiff of a real operatings systems class.

    For the record, Peterson's algorithm (published in 1981) is a much simpler solution to your problem. It's on page 56 of the Tanenbaum book, and also discussed in Stallings on page 213. There's a new 5th edition of the Stallings book, but the index will take you to the correct chapter/page in short order.

    --
    --
    Internet Explorer (n): Another bug -- that is, a feature that can't be turned off -- in Windows.
  12. Re:Cache choherency is NOT sufficient by Furry+Ice · · Score: 2, Insightful

    This is why closed-source drivers are a bad idea. There are a lot of coders out there who are so impressed with their own credentials that they just don't take the time to read and understand why their clever little hacks don't work. Then, when they try their driver on an architecture where their assumptions don't hold, they give up. The product is probably old and they make a business decision that it's not worth updating the driver for the new architecture.

  13. Too bad all programmers are sloppy. by Estanislao+Mart�nez · · Score: 2, Insightful
    C/C++ doesn't prevent you from coding secure, leak-free programs. All it does is shift the responsibility for security and memory management from the language to the programmer. If you're a sloppy programmer then, yes, you need a better language than C/C++.

    Experience demonstrates that, by and large, even very good programmers commit a sizeable number of these errors. Not to mention that ensuring proper security and memory management takes time; and time is money.