Slashdot Mirror


Pthreads vs Win32 threads

An anonymous reader writes "It's interesting when different people have different opinions. While I was searching for something on Intel's website, I came across an article on why Windows threads are better than Posix threads. Curiously, I also came across this article on why Posix Pthreads are better that Win32 threads. The thing is, both of these articles are written by the same author!

So who is right (metaphorically speaking?), or what has changed since the first article was written?"

280 of 385 comments (clear)

  1. quothe the poster by TinBromide · · Score: 5, Insightful

    "or what has changed since the first article was written?"

    Vista's release and a massive advertising campaign/increase in revinue for microsoft partners?

    --
    Is it sad that I am more likely to recognize you and your posts by your sig than your name or UID?
    1. Re:quothe the poster by Anonymous Coward · · Score: 3, Funny

      Get it right, assmuch. It's Linsucks or Linsux.

      Vista is the coolest OS ever. OS X 10.4 is a total rip off of it.

    2. Re:quothe the poster by should_be_linear · · Score: 5, Funny

      I have different theory: Dude has 2 separate threads in his brain. Comparing pthreads to Win32 threads only exposed dangerous race condition producing funny effects in his blog.

      --
      839*929
    3. Re:quothe the poster by Bright+Apollo · · Score: 1

      mod parent +1 funny, good insight!

    4. Re:quothe the poster by neomunk · · Score: 1

      I thought that was funny myself.

      Offtopic seems a bit harsh.

    5. Re:quothe the poster by Hal_Porter · · Score: 5, Funny

      Q)Why did the multithreaded chicken cross the road?
      A)to To other side. get the

      Q)Why did the multithreaded chicken cross the road?
      A)other to side. To the get

      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
    6. Re:quothe the poster by ThePhilips · · Score: 3, Informative

      I can only hope that's funny.

      This is [censored] reality. Nobody program for Windows because he likes to program for Windows: people do that mainly for money. "Work" they say.

      Whatever you appear to like in competing implementations is irrelevant: M$ and corporate decision makers leaves you no choice.

      And there are really only two choices: (1) you go insane and start loving whatever management tells you to love or (2) you search for another job. Since the guy is with Intel, he's likely to have good payroll and option (2) doesn't ring any bells.

      [ I hope you have noticed that "I love POSIX" post is from year 2003 - and "I love Windows" from 2006. But honestly it all looks more like joke. ]

      I'd say from personal experience, that threading in Windows is total mess. POSIX threads might look limiting - but on other side you need to resort to threads in *nix ... well you do not have to resort to threads all. It is your own programmer's choosing: to use threads or to use state machines and async I/O. Under Windows bugs plagued/plague/will plague async I/O and programmers have no choice other then to use threads for sockets and file I/O. So under Windows you use threads for everything (except GUI which is restricted to "main thread"), while in *nix it is norm to see threads only in applications which want to take advantage of multi-processor systems for heavy computational tasks: math, code cracking, video encoding, etc. Heavy I/O tasks in *nix are all single threaded: Apache, Squid, MySQL, PostgreSQL, postfix/sendmail/exim, etc. (Though most now support optional multi-threading too - for really busy servers.)

      --
      All hope abandon ye who enter here.
    7. Re:quothe the poster by Korin43 · · Score: 4, Funny

      What are you talking about? Plenty of people code for Windows, we call them "virus writers". ;)

    8. Re:quothe the poster by Courageous · · Score: 4, Interesting

      Nobody program for Windows because he likes to program for Windows...

      To the contrary. I work on Linux systems at work, and play on Windows, using .NET (C#) at home, for fun. .NET is a genuine pleasure to work with: a better java than java, I say. It may be an asset of the evil empire, and it may not be multiplatform, but I find those to be its only weaknesses.

      C//

    9. Re:quothe the poster by Korin43 · · Score: 1

      Er.. add in "for fun" somewhere in there..

    10. Re:quothe the poster by PitaBred · · Score: 5, Informative
      Did you notice the other similarities?

      Initial (2003) article:

      I've used both POSIX threads (Pthreads) and Win32 threads APIs and I believe that Pthreads has the better programming model of the two. While each threading method can create threads, destroy threads, and coordinate interactions between threads, the reason I make this claim is the simplicity of use and elegance of design of Pthreads. Let me illustrate with a few examples.
      And in the later article:

      I've used both POSIX threads (Pthreads) and Windows threads APIs, and I believe that Windows has the better programming model of the two. While each threading method can create threads, destroy threads, and coordinate interactions between threads, the reason I make this claim is the simplicity of use and elegance of design of the Windows threads API. This is all from the perspective of multithreaded code developers or maintainers. Let me illustrate with a few examples.
      It's not plagiarism because he copied from himself and just added a few edits, but c'mon... how lazy of a shill can you be?
    11. Re:quothe the poster by mustafap · · Score: 4, Funny

      >Get it right, assmuch. It's Linsucks or Linsux.

      It's GNU/Linsux you bastards! When are you going to get it right! Arghh!

      --
      Open Source Drum Kit, LPLC deve board - mjhdesigns.com
    12. Re:quothe the poster by BadERA · · Score: 2, Interesting

      I enjoy coding in Windows, and I do so for work, and on my own time. I enjoy being able to program multiple devices I happen to own -- Smartphones, Pocket PCs, desktops, servers, and soon probably a media center as well. I've done Java. I did VB6 for years. I've done a bit of C++. I've dabbled in Perl. I've written PHP when my arm's been twisted. I've been writing SQL against various datasources for years.

      When it comes down to it, I find I'm able to most quickly create a pleasant GUI app in Visual Studio, using .NET. Maybe that's my lack of exposure to Java tools ... please feel free to show me where I'm deficient here. I started out in BASIC 20 years ago, I've run various Linux installations. I can still, quite honestly, say that I do in fact enjoy programming in Windows.

      --
      I am, therefore you think.
    13. Re:quothe the poster by dnoyeb · · Score: 1

      Perhaps he was intentionally lazy. Perhaps someone above him told him to change it. And so he complied. Civil disobedience?

    14. Re:quothe the poster by PitaBred · · Score: 1, Informative

      ...civil disobedience is going against laws. I am fairly certain there was no governmental entity that told him to change his viewpoint on Windows threading.

    15. Re:quothe the poster by 0xABADC0DA · · Score: 5, Funny

      Q) Which came first, the multithreaded chicken or the multithreaded egg?
      A) They came at the same time, but the multithreaded chicken terminated first.

      Q) Which came first, the multithreaded chicken or the multithreaded egg?
      A) Neither; mt egg could not acquire chicken-lock from mt chicken. mt chicken could not acquire egg-lock from mt egg.

      Q) Which came first, the multithreaded chicken or the multithreaded egg?
      A) Multithreaded egg, but it overwrote its DNA while still in use and became mt turkey.

    16. Re:quothe the poster by dilvish_the_damned · · Score: 1

      We originally designed Clay Breshears to be a self documenting threading example.
      As it turns out it does not run stably on either platform.

      --
      I think you underestimate just how much I just dont care.
    17. Re:quothe the poster by Anonymous Coward · · Score: 2, Insightful

      This is one of those situations where I wonder if it is still plagiarism. They used their own words, something they are free to do, sure, but on the other hand, they didn't cite the original source, even though it is obviously derivative and self-contradictory. The fact it is their own work doesn't change the unacknowledged nature of the previous work. If it was merely re-using previous statements, fine. That's lazy. But to disagree with them is weird without some kind of acknowledgement of the fact.

      If this was a scientific journal article, and the editor and reviewers did their job, they might not call it plagiarism, but they certainly would insist that the original work be cited properly, and that the complete change of opinion be specifically acknowledged.

      Quoting yourself is fine. Silently hiding the fact that you completely disagree with your previous statements is sloppy. It's okay to change your mind, but usually you admit it.

    18. Re:quothe the poster by endianx · · Score: 2, Interesting

      You hit the nail on the head. .NET and C# are awesome. But as long as Microsoft controls them, I will always be suspicious. I use it at work, but I am often hesitant to use it for my personal programming, mostly because of the multi platform issue.

      My hope is that one day Java becomes as good. It certainly has the potential.

    19. Re:quothe the poster by Dragonslicer · · Score: 1

      Microsoft's .NET library may not work across platforms, but Mono does. As long as Mono doesn't get squashed by an army of lawyers, I'll continue to like .NET.

    20. Re:quothe the poster by ronnybrendel · · Score: 1

      I bet on that one.

    21. Re:quothe the poster by Courageous · · Score: 1

      Well. Interesting. See, I just write code to have fun. Besides, it may not run on all platforms, but it does run on 90% of all platforms, if you get my drift. What's the real multiplatform rub? That's been a crock for, like, ever. If you're willing to lose features to go multiplatform, try mono. They'll never be caught up with the M$ baseline, but at least they are C#.

      From a vanity point of view, the C#/.NET community is pretty weak in open source contributors, so it shouldn't be the desire to open source stuff that's causing a negative interaction with multiplatform... so what is? I admit it does suck to have to have M$ on a server. Be that as it may...

      C//

    22. Re:quothe the poster by dbIII · · Score: 1

      .NET and C# are awesome. But as long as Microsoft controls them, I will always be suspicious

      I'll add that I am also suspicous like the above poster not for any paranoid reason but due to MS having their languages as moving targets. VB for example started off resembling BASIC, moved to pascal and now looks a lot like java I believe - making reuse of old code unlikely.

    23. Re:quothe the poster by Listen+Up · · Score: 3, Insightful

      a better java than java, I say

      Bullshit. I develop full-time in J2SE/J2EE and now C# (.NET 2.0/3.0) as well. If you are just some beginner/non-developer, writing slightly more complicated Hello World applications, then you are not going to see any real difference between Java or .NET or . When it comes to writing real applications, such as applications leveraging massive amounts of long running transactional processes, enterprise message queuing systems (the existing MS message queuing systems are a joke), almost any SOA application (.NET 3.0 is getting better), almost any distributed scalable enterprise applications, the ability to develop an enterprise software solution on Windows and deploy it to Solaris/Linux/etc. with zero code changes (Mono you say...Not even close), etc. etc. etc. .NET is still 10 years back. How about a .NET equivalent to EJB 3.0? Not even close. Sure, the syntax of C# is nice, like Java, which it should be because Microsoft copied %99.999 of the syntax directly from Java.

      The features and functionality available in Java 6 are astounding and are aimed squarely at making J2SE on the desktop, making J2ME ubiquitous in mobile devices, as well as securely putting J2EE years ahead of it competition. Java 7 is looking to be even more exciting.

      For everyone whose last memory of Java is 10 years ago, you need to look at it again. Aside from basic single platform desktop applications, .NET is where Java was 10 years ago. Hell, Visual Studio is not even written in .NET nor any major application at this point (Office? IIS? Anyone?). Any real .NET app servers? And they certainly aren't running these applications on Mono. When I see Office running natively on Mono on Linux or OS X, I might be more interested. So Microsoft added automatic memory management and a common language runtime (with the intent to allow the possibility of cross-platform development on paper) to its main development languages. Yay. That doesn't make .NET equal to Java.

      All of the enterprise .NET developers at the company I work at as well as many of our clients are excited about .NET 2.0/3.0 web services because .NET is finally starting to get services that have been available in Java for years. That is the true point of .NET in the development world. People on Slashdot need to stop drinking the beginner/non-developer kool-aid.

    24. Re:quothe the poster by aybiss · · Score: 2, Insightful

      To be clear, C# is a language specification and so is definitively as cross-platform as you get, and the only part of .NET not well supported by Mono is Windows.Forms (and of course the various SDKs like DirectX).

      My 2c - pThreads suck ass. There's nothing worse than looking at 1000 Java 'processes' on your JSP server and wondering which ones will die if you kill one. It also makes it hard for the OS to figure out that App X hasn't had any CPU time for over 500ms.

      --
      It's OK Bender, there's no such thing as 2.
    25. Re:quothe the poster by ThePhilips · · Score: 1

      Maybe that's my lack of exposure to Java tools [...]

      Off-topic. I have whole department sitting one floor below who would call you "luck bastard." Hint: they work with Java tools all the day.

      Windows programming might be pleasant - if requirement are set well and fit into general M$Windows concepts. I had experience were people tried to best themselves with every new release and Windows was - to put it politely - "inadequate". e.g. for how long standard functions exist to open jpeg image in Windows? or png? or simple grids? or pdf? or ogg? You have to code it all by yourself. For one application - it is still O.K. For two, three - somewhat O.K. But for more it become PITA. Windows program are like snowballs of libraries: covering all what Windows didn't supported since Win9x era. Under Linux at least you do not have snowball effect and all trivial functions are in one way or another can be found in system. Though you still get all the pleasantries of multiple versions of different APIs.

      --
      All hope abandon ye who enter here.
    26. Re:quothe the poster by doktorjayd · · Score: 1

      +10

      and to think i threw mod points at some crap yesterday..

      the other thing about .NET vs. java ( and its the same in any language/platform debate ) is the availability of libraries and a pool of talented developers. i'm sure over time ther'll be more .net types around, but really, apart from cloning all the java libraries and frameworks ( see NHibernate ), .NET just doesnt have the pull or the momentum.

      that, and i tell ya the slop i've seen passed off as '.NET' in the last couple of years which turns out to be vbscript in asp pages, its surprising that anyone takes .NET seriously at all.

      even better with java it allows you to code to a specification ( j2ee ) rather than an implementation, and you invariably end up with truely portable code which can be deployed to a variety of vendor platforms, containers and jvms. voila! no vendor lock in!

      oh, and sun gpl'ing their implementation should put the icing on the cake. theres a few posts above that waffle on about being able to run on 90% of the market ( ie: windows [pardon the pun] ), i'll forgive their ignorance and point at the sun e10k's costing megabucks which java apps are king. know what else? i can usually deploy the same app on my home server ( retired p3 desktop) in tomcat with confidence it'll run.

      try firing up a meaty .net app on an 8 year old machine with 1/2 a gig of ram and see how far ya get. ( include db, web and app container )

    27. Re:quothe the poster by Courageous · · Score: 1

      *shrug*. I write code in Python, too. Most of these higher level languages have incoherent SDKs, so you have to take the bad with the good.

      C//

    28. Re:quothe the poster by Courageous · · Score: 1

      For everyone whose last memory of Java is 10 years ago, you need to look at it again. Aside from basic single platform desktop applications, .NET is where Java was 10 years ago.

      Your comments about J2EE are fair. Microsoft simply does not have that level of an ecology in that space.

      For my hobby time, I use .NET to write fat desktop clients and raw server code for which J2EE or SOA would be of no interest. Down in the fundaments, C# was a rethink of Java, not just a copy, and it improved on a lot of things which Java got wrong. Some of them are pretty simple. Like the brain-dead com.company.package.subpackage carpal-tunnel crap. And so forth. C# is more modern than Java and has had a chance to learn from Java's mistakes. This plainly shows.

      BTW, about Microsoft copied Java litany: it's tired, old, maladroit, boring. Give it up.

      C//

    29. Re:quothe the poster by FrostedChaos · · Score: 1

      My 2c - pThreads suck ass. There's nothing worse than looking at 1000 Java 'processes' on your JSP server and wondering which ones will die if you kill one. It also makes it hard for the OS to figure out that App X hasn't had any CPU time for over 500ms.

      You are confused. Pthreads is a cross-platform API with a bunch of different implementations, including ones for Linux, Windows, BSD, and some embedded platforms.

      LinuxThreads is the crappy threading library that Linux used to use, which treats threads as processes. Luckily, new Linux systems now come with NPTL, which doesn't have this problem.

      --
      "Any connection between your reality and mine is purely coincidental." -Slashdot
    30. Re:quothe the poster by aybiss · · Score: 1

      Ah-ha! I stand corrected. My experiences with this were under Debian, which I would have thought to be using the latest threading model, but if what you're saying is correct it definitely wasn't.

      Google and I will now go and get my facts straight...

      --
      It's OK Bender, there's no such thing as 2.
    31. Re:quothe the poster by jsiren · · Score: 1

      The real world:

      $ ./joke question.txt answer.txt
      Q) WhichQ) Which came first, came the first, multiththereadedmultithreadedchickenchicken    or the multithreaded the multithreaded egg? egg?^M^M
      A) TheyError: Could not acquire exclusive lock on answer.txt.cameError: Could not acquire exclusive lock on aswer.txt.at theError: could not acquire exclusive lock on answer.txt.sameSegmentation fault (core dumped)
      $

      --
      Usage: km/h for speed (kilometers per hour); kph for very slow impulses (kilopond hours).
    32. Re:quothe the poster by dlymper · · Score: 1

      ... or the writer's brand new Swiss checking account?

      --
      - "I say the whole world must learn of our peaceful ways...by force!!" Bender B. Rodriguez
    33. Re:quothe the poster by 0xABADC0DA · · Score: 1

      Grandparent poster just called and he wants his joke back.

    34. Re:quothe the poster by try_anything · · Score: 1

      Is it safe to bet on Mono? Linux developers I know seem to be assuming that MS will find a way to keep Mono one step behind. They like .NET and would love to develop for it, but they're scared to.

      They're also scared that the .NET ecosystem developed by Windows programmers will have all kinds of weird and unexpected dependencies... that every web services framework and cryptography library and logging API will end up requiring Windows Forms and DirectX. (After all, every Windows program seems to hide all its functionality inside GUI controls, which makes just as much sense.)

    35. Re:quothe the poster by angel'o'sphere · · Score: 1

      Well,

      I tend to follow more your parent.

      Some of them are pretty simple. Like the brain-dead com.company.package.subpackage carpal-tunnel crap.
      Thats only your impression, I see nothign wrong with it and hate the way of C# namespaces copied from C++.

      And so forth. C# is more modern than Java and has had a chance to learn from Java's mistakes. This plainly shows.

      Yeah, it would be great if you could give us 10 points ... or 5 even. I see absolutely nothing in C# that is better or more elegant or more advanced in relation to Java, except delegations, but for that I had prefered true closures and not the brain dead way C# does it.

      No offense, I really would like to know what parts of C# you find well done.

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    36. Re:quothe the poster by aybiss · · Score: 1

      Is it safe to bet on Mono? Linux developers I know seem to be assuming that MS will find a way to keep Mono one step behind. They like .NET and would love to develop for it, but they're scared to.

      Well, .NET 3.0 has just come out and Mono still doesn't have Forms 2.0 support, but then again Gtk# 2.8.3 is available. As a primarily Windows developer, I'm looking to these developments in order to go cross-platform with my code. I mean, .NET 1.1 support is basically complete. The only thing you're really going to miss, even if you were completely stuck with .NET 1.1 support only (which you aren't) is generics.

      They're also scared that the .NET ecosystem developed by Windows programmers will have all kinds of weird and unexpected dependencies... that every web services framework and cryptography library and logging API will end up requiring Windows Forms and DirectX. (After all, every Windows program seems to hide all its functionality inside GUI controls, which makes just as much sense.

      This is 100% pure FUD. The .NET API is at least as clean and clear-cut as Java's, if not more-so. Dependencies like this really don't exist, I can guarantee you.

      And if you aren't happy with event based programming of Forms that's fine, because they aren't locking you into it, just making it incredibly easy to throw together a simple interface. You also have to remember it is the only way a chump programmer can be restricted to behavious that lead to useable apps (given how terrible the MS windowing foundation is to begin with) and maintainable code. My hat really goes off to .NET and VS2005 in that respect.

      Take a look at what people got themselves into with MFC in C++, and then see how well laid out a chump app is with .NET and C#. It still may not be a simple task to get a .NET application working under Linux, but look how far we've come.

      One thing that would really drive Mono along would be if all these Linux scaredy-cats stopped hesitating and started using Mono and MonoDevelop (fantastic project) more seriously.

      Great discussion by the way.

      --
      It's OK Bender, there's no such thing as 2.
    37. Re:quothe the poster by try_anything · · Score: 1
      I don't mean that the official .NET APIs will be riddled with dependencies, but that the open-source ecosystem (which is very important in Java, less so now that many official APIs have copied ideas and designs from open source projects) will have these crazy dependencies. I've ported a couple (okay, exactly two) chunks of Windows code to Linux, and both times all of the functionality was in GUI controls, even though it wasn't intrinsically dependent on a GUI. The programmer just assumed it would always be used as part of a GUI application, and he designed it to be impossible to use any other way. In one case the programmer wasn't a total chump. The application scanned, probed, and configured a class of hardware devices (using WinDriver, a cross-platform PCI interface library, in case you're wondering why PCI code was portable to Linux), and all the code to twiddle the registers and read the PCI configuration spaces and so forth was in button-push handlers. The app ran solidly, looked nice, and seemed professional in every way except the bizarre code organization. If this is a common practice in the Windows world, then Mono developers are going to have a hard time benefiting from .NET open-source projects.

      OTOH, it seems that many of the Boost developers are Windows guys, so Windows programmers can't be stereotyped as modularity-impaired GUI addicts.

      Take a look at what people got themselves into with MFC in C++, and then see how well laid out a chump app is with .NET and C#.

      Forgive my cynicism, but hasn't Microsoft ported all their wonderful spaghetti-producing IDE wizards to .NET? Won't .NET development be just as "easy" and "productive" as MFC programming?

    38. Re:quothe the poster by rjshields · · Score: 1

      Your post is so heavily laden with management terms like "enterprise" and "leverage" I think it must be bullshit. And you like EJB, which is the biggest joke ever. EJB 3.0? Do yourself a favour and use hibernate. I'm a Java developer but you just sound like a fanboy, we don't need no stinking fanboys.

      --
      In this world nothing is certain but death, taxes and flawed car analogies.
    39. Re:quothe the poster by Courageous · · Score: 1

      I really would like to know what parts of C# you find well done.

      Delegates (old style)
      Delegates (new style, with closures)
      Symmetric reference system... both practical AND clear.
      Autoboxing.
      Properties
      Jagged and non jagged arrays.
      generics
      structs (yes sometimes the stack really is better)
      enums
      sensible support of abort-case (fallout case) goto (Hejlsberg actually read Djikstra... gasp!)
      P/Invoke.. hate it if you like, but it's very practical

      Some things I don't like:

      Access semantics. Java is better, with default package visibility (default package visibility strikes me as "correct").

      The format system, which is the worst one I've ever used. Why do people keep reinventing printf?

      The spurious changing of keywords from Java for change's sake. Annoying.

    40. Re:quothe the poster by aybiss · · Score: 1

      I see what you're getting at. It's a very good point. I do think though that if you are thinking about cross-platform or even just well modularised design you would separate the business logic from the GUI, but I am in the exact situation you're describing right now. My app works just great but even though I've been conscious of it I know there is still code in the GUI that should be in the core. Still, there's only so much your IDE can do for you, and if you just want to write a Windows only app, you can do it a hell of a lot faster with Visual Studio than just about any other tool (disclaimer: I use VS for basically everything and haven't played with Eclipse or MonoDevelop or anything else for more than a few minutes).

      As for .NET versus MFC, there really is no comparison. The MFC wizards were quite capable of doing all the foot shooting for you, whereas the .NET ones produce partial classes etc. and don't generally backfire and produce code that won't compile. They're also a lot less bitchy about having their output modified by you. The code for .NET generated Forms looks kinda like an AWT class from Java, where as MFC used its own special syntax, not to mention being one of the ugliest APIs for Windowing ever. To debug .NET forms is generally easy, whereas with MFC crashes that did occur were often found inside system classes that could appear to be broken themselves.

      I know my knowledge and skills have improved a hell of a lot since the MFC days, but I am sure the improvements are not all me. :-)

      --
      It's OK Bender, there's no such thing as 2.
    41. Re:quothe the poster by angel'o'sphere · · Score: 1
      Hm,

      I don't want to argue about what is better (than the Java equivalent, e.g. java has auto boxing and enums as well) or not, but some more explanations would be cool:

      • What do you mean with "Symmetric reference system"?
      • What do you mean with "Jagged and non jagged arrays"? Hm, think I got it, Java only has Jagged Arrays and no jagged ones ... still wondering why one needs non jagged ones ;D
      • sensible support of abort-case, what is that? A special "break"?


      Only first and last question I find hard to get clear via google.

      Well, to give my point of view in return:
      • non virtual methods by default
      • calling the C# finalizer a destructor, while it is a finalizer (and the trouble it causes to teach this to a) C++ users and b) to C++.NET users who have a destructor AND a finalizer)
      • the need to write override ... the option to write new to introduce a new method, which makes no sense at all, and the fact that the default behaviour is not override but new
      • basically (even when the inventors and article writers try to claim the opposite) the same generics system like Java, instead of having a proper template system like C++
      • no multiple inheritance, with templates together this would be true win
      • the gui library sucks in relation to Swing, and more important the GUI builder is a mess (if I rename either an event or a method in either the GUI builder or the source editor, non of the others gets updated. A bit understandable from an text editor point of view but not from the GUI builders point of view)
      • class loading


      Thats the stuff I don't like ;D but there s much more, which I luckily forgot.

      angel'o'sphere
      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    42. Re:quothe the poster by Courageous · · Score: 1

      "Symmetric reference system"; C# can pass value types by reference. The caller and the callee must agree and both label it "ref". This makes the semantics clear to the code reader, who is given an immediate signal that his value type may be changed as a consequence of the invocation of the method.

      Non jagged arrays have much higher performance than jagged arrays due to memory adjacency issues. That's why every single high-performance-computing library in the world uses them.

      "abort case goto". Contrary to what your computer professor told you, there are a few special use cases for "goto" that are not only "bad," but rather are "good." C# supports them.

      Writing "override" is helpful, as it (like the ref case above), makes clear the intent and signals to future readers the semantics of the situation.

      Swing is slow. Everyone knows that. That's why people mistakenly label the entire Java suite as "slow," because Swing is godawful slow.

      Anyway. I agree that there are some better things in Java. "Default package visibility" is top on my list. I can see what you mean about class loading.

      As for the "no multiple inheritance" issue I agree... I poisonously agree! :) Every argument I've heard against it is compiler authors whining about how hard it is to do. Well, whine, whine, whine. Works fine in Python and other dynamic languages, these guys need to grab a clue.

      BTW, in my op, I mixed and matched the terms .NET with C#. That was a mispeak. It is only purely C# (the language) that I find better than Java (the language). JDK > SDK. And so forth. In fact, until the (recent) SDK 2.0, the SDK was an embarrassment. You should have seen the container classes! Hello, anyone home?

      I suppose if I were to summarize in a nutshell why I like C# better than Java, I would say that it appears to me that the author was more concerned with the practical job of day to day program than he was concerned with maintain some kind of zealous adherence to "purity".

      Technological zealotry always turns me off.

      C//

  2. switch? by raffe · · Score: 1, Interesting

    Looks like he just switched the words in the articles...?

    1. Re:switch? by Anonymous Coward · · Score: 1
    2. Re:switch? by Anonymous Coward · · Score: 2, Interesting

      After reading both entries, I went to close the tab and was given a chance to provide feedback on intel's site. After clicking on all the survey questions, I left this comment:

      Why not compare this (http://softwarecommunity.intel.com/ISN/Community/ en-US/forums/post/840096.aspx) with this (http://softwareblogs.intel.com/2006/10/19/why-win dows-threads-are-better-than-posix-threads/)

      The WaitOnMultipleObjects() is the only diff, and latter the article is just a blatant recycling of the former; not very credible.

      [tt]

  3. $Money$ by ArcherB · · Score: 4, Insightful

    So who is right (metaphorically speaking?), or what has changed since the first article was written?"

    Who was paying for it.

    --
    There is no "I disagree" mod for a reason. Flamebait, Troll, and Overrated are not substitutes.
    1. Re:$Money$ by Anonymous Coward · · Score: 1, Funny

      I'm used to reading comments on slashdot, but this one confuses me -- what is smoneys?

    2. Re:$Money$ by abradsn · · Score: 1

      Oh, I know this... let me guess the first one... I bet it was the Pthreads rule the world commission!

  4. different by l3v1 · · Score: 1

    It's interesting when different people have different opinions.

    Not so long ago, to some extent even today, there have been certain parts of this planet where that could have been called interesting indeed, but that only by some elements of their governments. Now, you calling that interesting makes an interesting picture of you.
     

    --
    I am putting myself to the fullest possible use, which is all I can think that any conscious entity can ever hope to do.
  5. Pthreads = Win32 threads? by arlo5724 · · Score: 5, Funny

    ( Pthreads >= Win32 threads ) and ( Win32 threads >= Pthreads ) => Pthreads = Win32 threads

    1. Re:Pthreads = Win32 threads? by anci_pants · · Score: 5, Funny

      I think you mean Pthreads == Win32 threads.

      Although, it may be true that Win32 threads = Pthreads (which may account for the improvement)

    2. Re:Pthreads = Win32 threads? by newt0311 · · Score: 1

      lisp is the only language I can think of which uses the `=' sign as equality. everything else I know uses the `==' operator for equality testing (in some form). Any othr languages like lisp?

    3. Re:Pthreads = Win32 threads? by AmX · · Score: 2, Insightful

      Pascal?

    4. Re:Pthreads = Win32 threads? by Anonymous Coward · · Score: 1, Insightful

      Smalltalk, Pascal and Ada come to mind first. All use := for assignment

    5. Re:Pthreads = Win32 threads? by evil_Tak · · Score: 2, Funny

      Visual basic. Or are we only counting real languages?

    6. Re:Pthreads = Win32 threads? by lwriemen · · Score: 1

      REXX, PL/1, Basic, Pascal, Modula, Oberon, ...

      It would be interesting to see which is used by more languages, '==' or '='? ;-)

    7. Re:Pthreads = Win32 threads? by Jerry+Coffin · · Score: 1

      REXX, PL/1, Basic, Pascal, Modula, Oberon, ...

      Interesting that you'd mention PL/I. PL/I allowed you to use '=' for either assignment or comparison (like BASIC does). Unlike BASIC, however, it also had ':=' for assignment to deal with some ambiguous situations. One I always loved was an expression like 'x=y=0;'. Now in just about any semi-sane language this would obviously assign 0 to both x and y.

      In PL/I, however, that's not what happens -- by its rules, the first '=' is an assignment, but the second is a comparison -- so it compares y to 0 and then sets x to either 0 or 1 to indicate the result. If y was 0, x becomes 1, but if y was some other value, x becomes 0. Regardless of their previous values, after executing 'x=y=0;', x cannot equal y!

      As I said above, you could use ':=' to deal with this -- either 'x:=y:=0;' or "x=y:=0;' gave what you'd normally expect.

      --
      The universe is a figment of its own imagination.
    8. Re:Pthreads = Win32 threads? by Richard+Steiner · · Score: 1

      The interpreted mainframe macro language I use a lot in the Unisys mainframe world (@CALL) uses "=" or "!=: for case sensitive equality and inequality, "eq" and "ne" for case insensitive equality and inequality, and ":=" for variable assignment.

      All in all, it's quite clean synctactically. A manual for the language can be found here:

          http://www.visi.com/~rsteiner/2200stuff/callprm.ht m

      --
      Mainframe/UNIX Bit Twiddler and long time Windows/Linux Hobbyist.
      The Theorem Theorem: If If, Then Then.
    9. Re:Pthreads = Win32 threads? by SocialWorm · · Score: 1

      I believe EUPHORIA uses '=' for both assignment and testing based on context, but I haven't used it for some years, so I may be wrong about that.

      --
      My Blog: http://nic.dreamhost.com/
    10. Re:Pthreads = Win32 threads? by recursiv · · Score: 1

      Many manifestations of BASIC have the exact same behavior for x=y=0.

      --
      I used to bulls-eye womp-rats in my pants
    11. Re:Pthreads = Win32 threads? by siDDis · · Score: 1

      A very common cowboy language use === because you have to tell that the variables is of equal types.....

    12. Re:Pthreads = Win32 threads? by jadavis · · Score: 1

      SQL
      OCaml

      --
      Social scientists are inspired by theories; scientists are humbled by facts.
  6. Look at the dates, Dude. by DelawareBoy · · Score: 3, Insightful

    The blog entry that points out the superiority of Win32 threads is dates to October 2006. The PThread example is a reply to a posting from 2003. I have a feeling that as the author worked more and more with the different threading models, he seems to have a more matured opinion. However, this being Slashdot, the Win32 Threading model is by definition inferior, since Microsoft has no intelligent engineers whatsoever and the author of the article was originally correct and should have never have looked further.

    1. Re:Look at the dates, Dude. by Anonymous Coward · · Score: 5, Informative

      Except that the 2006 entry is essentially a structural copy of the 2003 entry, just with some wording changes. He even uses the same arguments against PThreads in the second entry that he used to support it in the first. Weird...

    2. Re:Look at the dates, Dude. by AKAImBatman · · Score: 5, Interesting

      I have a feeling that as the author worked more and more with the different threading models, he seems to have a more matured opinion.

      Normally I'd agree with you. But if you read both articles, you realize that his intentions may be a bit less honorable. The Win32 article is the exact same article, but with the conclusions changed. Maturing opinions usually result in some discussion of why one has changed their mind (even if it's only mentioned in passing) and/or a deep explanation of what caused their mind to change. This smells more like an attempt to play both sides.

      Of course, it could be that the author is simply not comfortable with writing. He could be looking to make a quick buck by taking a simple forum post of his and modifying it to reflect his current opinion. It's worth giving him the benefit of the doubt on, but I am certainly suspicious.
    3. Re:Look at the dates, Dude. by AKAImBatman · · Score: 4, Insightful

      I think you misunderstand. My suspicion stems from the author's motivations, not whether Microsoft is involved or not. His first post was made to a software forum, where it's unlikely he was compensated for it. His second post was made to a semi-official corporate "blog", which raises questions about if he's being paid or not. Being an author myself, I know that's it's incredibly easy to step over the lines of journalistic integrity in exchange for that few hundred dollars of pay.

      The question is, did the author really change his mind, or is he writing the conclusions that he knows will net him an income? If it's the former, he really should have expanded his article to prevent this sort of issue. If it's the latter, then the author is untrustworthy and should no longer be paid to provide his opinion in any professionally written form.

      Microsoft never enters into the equation here, save for the fact that some entities may have a monetary interest in promoting Microsoft Windows -OR- Linux. (There's money in both directions.) That being said, it is sad that this issue may never have come up if the order of the articles was reversed. Slashdot is very pro-Linux (something which I am ambivalent about), meaning that it would have likely been seen as a win rather than the questionable journalism it is.

    4. Re:Look at the dates, Dude. by ultranova · · Score: 3, Insightful

      This being Slashdot, anything that is remotely pro-Microsoft MUST be viewed with suspicion, even if the author of the article does not work for Microsoft. We can't let them Win. (No Pun Intended)

      I certainly hope that someone who first claims that "Separate data types" make Pthreads superior to Win32 threads and then turns right around and claims that they in fact make Pthreads inferior to Win32 threads gets viewed with a certain amount of suspicion, on Slashdot as well as everywhere else.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    5. Re:Look at the dates, Dude. by Dogtanian · · Score: 2, Insightful

      This being Slashdot, anything that is remotely pro-Microsoft MUST be viewed with suspicion, even if the author of the article does not work for Microsoft. Yawn.... are you trolling, or stupid, or both? The post you replied to gave a pretty good justification for not taking *either* article at face value.

      Regardless of which threading model is better, the articles are contridictory, yet written just 16 months apart, with large parts similar and the author failing to acknowledge, let alone explain, his change of mind. In that light, they smack of a lame and insincere attempt to get attention.
      --
      "Slashdot - News and Chat Sites Deviant". (Click "homepage" link above for details).
    6. Re:Look at the dates, Dude. by itsNothing · · Score: 1

      It is also true that Microsoft has paid to have "research" done which is more favorable to Microsoft products. Moreover, the "money trail" has often been brought to light AFTER the favorable research has had its first viewing by the public.

      Microsoft has some of the best researchers money can buy. I wonder, sometimes, if this is more to keep them "off the market" than it is to use their knowledge. You know, buy your competition and muzzle them.

    7. Re:Look at the dates, Dude. by jimstapleton · · Score: 1
      NOTE: This quote is not the previous authors comment, but a modification.

      Normally I'd agree with you. But if you read both articles, you realize that his intentions may be a bit more honorable. The Win32 article is the exact same layout, but with pieces of content and conclusion changed. Maturing opinions usually result in some discussion of why one has changed their mind (even if it's only mentioned in passing) and/or a deep explanation of what caused their mind to change. This smells more like he was embarrased about his old oppinions.

      Of course, it could be that the author is simply not comfortable with writing. He could be looking to make a quick buck by taking a simple forum post of his and modifying it to reflect his current opinion. It's worth giving him the benefit of the doubt on, but I am certainly suspicious. The content of this quote is exactly the same as the content of the parent like the content of the two articles are exactly the same.

      There's a lot of different information in them, they just follow a very similar, and possibly copy and pasted format. Normally I would agree that a discussion of the change of veiw would be appropraite, and actually I still do agree, but your reply was a bit harsh. The two articles to me combine to say:

      (1) pthreads are *MUCH* easier to learn for a novice programmer, and can get most tasks done just fine.
      (2) Win32 threads are *MUCH* harder to learn [very believable after looking at some of the Windows API], but have a bit more functionality and flexibility.

      It may also relate to a change in the Win32 thread API, but I doubt that would have changed so significantly.

      Or you could be right, he could be a jerk out for a buck, but I doubt it's as clear-cut as your post suggests.
      --
      34486853790
      Connection too slow for X forwarding? Try "ssh -CX user@host"
    8. Re:Look at the dates, Dude. by DelawareBoy · · Score: 1

      While that's very true, what if the "research" happens to be correct? Or at least fairly positive? Agreed, most research studies have uncertainty to them (correlation vs. causation to name only one), but even if Microsoft paid for X research, do you really think, say, that a group of GNU-affiliated University Professors would actually have an unbiased view when comparing, say, Open Office to Microsoft Office? Even though there is no money changing hands?

      I guess, for this article, it's immaterial, since it was not a study, rather, someone's own opinion through their work.

    9. Re:Look at the dates, Dude. by gladish · · Score: 1

      Yes, but it's a little odd that both articles are so similar in wording. The first paragraph is basically a cut and paste. I tend believe what you've stated. The author probably worked a lot more with win32 for the past few years and became very familiar with the API. I, on the other hand, have been working with posix threads for about 5 years now, and the idea of a signal being persistent like that seems very strange. I've become so used to writing.

      pthread_mutex_lock(m);
      while (invariant)
              pthread_cond_wait(m,c);

      pthread_mutex_unlock(m);

      From what it sounds like, I'd have to unset that condition in there somewhere. One other thing that I don't like is the idea of referring to objects of different types (mutexes and conditions) with the same type of "Handle". Seems to be counter to the c++ philosophy of type safety. What happens when I notify a mutex? This simply wouldn't compile using the pthread api. e.g. I couldn't write pthread_cond_notify(m) and expect that to compile.

    10. Re:Look at the dates, Dude. by TheRaven64 · · Score: 1

      I learned Win32 threads first, and I wouldn't say they are particularly hard. I then learned POSIX threads, used them for a bit, and then had to help someone else with their Win32 threads code. I found this quite hard, since Win32 threads seemed to be missing a few of the things I routinely used in POSIX threads. Do Win32 threads have condition variables these days?

      --
      I am TheRaven on Soylent News
    11. Re:Look at the dates, Dude. by JakusMinimus · · Score: 1

      ... We can't let them Win. (No Pun Intended) Then why the gratuitous capital W?
      --

      You can be an atheist and still not want to succumb to some weird cross-over sheep disease -- AC
    12. Re:Look at the dates, Dude. by Anonymous Coward · · Score: 1, Funny

      Everytime I see a win32 API I have to weep. I'm really wondering what drugs their engineers are on, and they can't be good ones.

    13. Re:Look at the dates, Dude. by Slashcrap · · Score: 1

      Slashdot is very pro-Linux

      What else is it going to be? Pro-Microsoft? Why?

      That would make sense if we were all MS shareholders and they were out of money for advertising. Otherwise it's just giving free PR to a company that doesn't even know you exist.

      Would you be comfortable reading a pro-Halliburton or pro-Pfizer website written by somebody who isn't even being paid to shill for them? I'd run a mile on the assumption that that person is clearly fucking insane.

      I assume you must disagree.

    14. Re:Look at the dates, Dude. by Overly+Critical+Guy · · Score: 2, Insightful

      This being Slashdot, people like you don't read the article. If you had, you'd see that it's the very same article but with some terms flipped, thus the suspicion. I understand that you're trying to appear enlightened by accusing everyone of bias, but it only made you look foolish.

      --
      "Sufferin' succotash."
    15. Re:Look at the dates, Dude. by TopherC · · Score: 2, Interesting

      If the arguments in these articles are actually interchangeable, then either:

      1) These arguments have no rational basis, and both are BS (unjustified opinions).

      2) There are serious factual errors in at least one article.

      I wonder which one of these is closer to the truth? I'm guessing it's #1. Either way, the author can no longer be taken seriously.

    16. Re:Look at the dates, Dude. by Xabraxas · · Score: 2, Insightful

      While that's very true, what if the "research" happens to be correct? Or at least fairly positive? Agreed, most research studies have uncertainty to them (correlation vs. causation to name only one), but even if Microsoft paid for X research, do you really think, say, that a group of GNU-affiliated University Professors would actually have an unbiased view when comparing, say, Open Office to Microsoft Office? Even though there is no money changing hands?

      The problem isn't the outcome or who funded the research as much as it is about disclosure. It is perfectly ok to do your own studies and publish the favorable results but you have to disclose that you funded the study. Otherwise it is just dishonest. Even if Microsoft didn't specifically ask for favorable results the researchers have a financial incentive to produce good results for Microsoft so they can get paid again when Microsoft wants another study done.

      --
      Time makes more converts than reason
    17. Re:Look at the dates, Dude. by GreyWolf3000 · · Score: 1

      I think the drug is called lsdpcpDrugEx.

      --
      Slashdot: Where people pretend to be twice as smart as they really are by behaving like children.
    18. Re:Look at the dates, Dude. by julesh · · Score: 1

      If the arguments in these articles are actually interchangeable, then either:

      1) These arguments have no rational basis, and both are BS (unjustified opinions).

      2) There are serious factual errors in at least one article.


      The arguments are rational, they just pick a side in an engineering tradeoff from which each side is just about as easy to justify -- higher degree of type safety vs flexible use of a small number of primitives. (Unusually, that's Windows playing the 'small number of primitives' card this time, whereas it's more usually a Unix philosophy) As with all such things, which side is best depends on a lot of factors, most notably the programmer's personality. And if this guy has changed his personality to match the Windows way of doing things over those three years of being exposed to Windows, I don't see any reason this should reflect on his reputation.

    19. Re:Look at the dates, Dude. by fuliginous · · Score: 1

      I kind of got the feeling I would expect the Win32 threads to be C++ and the Pthreads to be C. So if he's had a shift to C++ and bought into it of course the old limitations of a C library are going to be inferior as an API. But is it possible to write a C++ cover for the Pthreads that would resolve all his claims and maintain the Pthreads advantages from the original article.

    20. Re:Look at the dates, Dude. by AKAImBatman · · Score: 1

      Your argument is a classic ad homnim attack.

      Your grasp of the term "ad homnim[sic]" leaves something to be desired.

      The question really is (regardless of who wrote it and why he wrote it) Is one threading model better than the other.

      Obviously you didn't read the articles. The answer is: Win32 is better because it's a high level API. PThreads is better because it is not a high level API.

      Talk about a split personality.

      What is the quality of what the author wrote?

      Poor at best. (Why didn't you *read* it for yourself?) But that wasn't a problem when he was just expressing his opinion. When he resorted to modifying three words per paragraph to express the exact opposite opinion, his quality dropped to nothing more than junk copy.

      Now, riddle me this Mr. AC: How can I take an opinion seriously when in one article the author says that a particular attribute is a detriment to one API over the other, while in the next article he tells me that the same attribute is an asset of one API over the other?
    21. Re:Look at the dates, Dude. by AKAImBatman · · Score: 1

      In particular I was speaking of "Ad hominem circumstantial" which asserts that the merit of the discussion is predicated on why the discussion is being held rather than the value of the discussion.

      You seem to misunderstand. I was replying to someone else who made the statement that the author must have changed his mind. You can argue that his post was about "ad hominem circumstantial", but my own was distinctly on the topic at hand.

      The answer is: Win32 is better because it's a high level API. PThreads is better because it is not a high level API."

      Is both silly and insulting.

      It is neither silly nor insulting when it is, in fact, the author's conclusions. If you wish to argue that he did not make statements to that effect, then be my guest.

      If the question is "Do I think the author has a valid argument?", I expect I could answer that and spend quite some time talking about the merits of the position.

      To be perfectly honest, your opinion holds very little weight with me. You are posting as an anonymous coward, which gives no basis for trusting your opinion. If you think you have a logical argument rather than just your thoughts on the issue, then you are free to make it.

      Which is better Pthreads or Win Threads?

      I am not looking to address that question. Each API has its finer points, and is worth investigating. A good article would take a good hard look at both and give an answer dependent on the situation. My only purpose in entering this conversation was to point out the evidence against another poster's assertion that the author simply changed his mind.

      Now please, do try to stay on topic.
    22. Re:Look at the dates, Dude. by AKAImBatman · · Score: 1

      You choose to denigrate the merit of my opinion based on who I am (or rather my failure to login).

      I am not denegrating your opinion. Only pointing out that I have no basis to trust it. As the old saying goes, "Opinions are like assholes. Everyone has one."

      There is a reason why only those who carry credentials are able to provide "expert" testimony or "expert" consulting. They can show that they have the experience to show what they are talking about. Your failure to "log in" as it were, means that you do not have an credentials with which to rely upon when giving an opinion. You can give it, but it will be just so many words in the wind.

      However, that does not stop a provably logical argument, something for which I invited you to produce. So where is it?

      Classic ad hominem attack.

      Again, you fail to understand the meaning of the term "ad hominem". Or in this case "argumentum ad hominem".

      This is ad hominem:

      > You are an AC and a troll, therefore your opinion about PThreads must be false.

      This is what I said:

      > You provide insufficient credentials to show an expert opinion. Please resort to using a logically provable argument instead.

      That is not ad hominem, but rather a matter of authoritative sourcing. If you do not understand the difference, then your education is not as complete as you seem to think it is.
    23. Re:Look at the dates, Dude. by AKAImBatman · · Score: 1

      Ad hominem tu quoque, my trollish friend. You replied to me, remember?

      I will never understand why you people start these arguments. You're obviously an intelligent person, so why twist meanings and facts to get the other party to respond? Seems like a waste of talent.

  7. From the obvious dept by hey · · Score: 5, Funny

    If you are programming on Widows I would recommend Windows threads, while on *nix Pthreads are a better choice.

    1. Re:From the obvious dept by Hal_Porter · · Score: 5, Funny

      Windows threads work on BOTH platforms, Windows XP/Vista and Windows CE.

      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
    2. Re:From the obvious dept by Anonymous Coward · · Score: 2, Insightful

      ... and what if you are trying to write portable multi-platform code? pthreads is the obvious choice...


      Ummm... did you mean to say Java Threads?

    3. Re:From the obvious dept by iabervon · · Score: 1

      Actually, the Windows API (everything is a HANDLE) is a better fit for *nix (everything is a file descriptor) than the pthreads API. In fact, the thing that's really a pain about pthreads is that WaitForMul^W select doesn't work on pthreads objects, so there's no way for a thread to block on whichever happens first of a file descriptor being readable or a condition variable being signalled.

    4. Re:From the obvious dept by init100 · · Score: 1

      POSIX means "Portable Operating System" (no one is sure what the I & X stand for!)

      I = Interface. The X is more uncertain. Some people regard this as a tribute to Unix, but I don't think it is in the standard. POSIX is expanded to "Portable Operating System Interface" on the IEEE page, while it is expanded to "Portable Operating System Interface for uniX" on its Wikipedia page.

    5. Re:From the obvious dept by drinkypoo · · Score: 2, Funny

      If you are programming on Widows I would recommend Windows threads, while on *nix Pthreads are a better choice.

      If you are programming on Widows, may I suggest a chair? It's typically more comfortable.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    6. Re:From the obvious dept by Creepy · · Score: 1

      no - you want a platform based thread abstraction.

      I say this mainly because pthreads are _not_ thread safe with Windows threads and are only thread safe with the standard C function library. That alone should tell you you're asking for trouble if you use them with Windows.

      personally, I like both APIs for different reasons. I find pthreads much easier and faster to set up and tear down. Windows has a lot more robust features that I had to re-implement myself for pthreads, such as a thread pool API (sometimes these are called worker threads).

    7. Re:From the obvious dept by dnoyeb · · Score: 1

      Doubt it since java threads will use the threading library of the OS the VM is running on. Unless you are talking some form of embedded Java.

    8. Re:From the obvious dept by BalkanBoy · · Score: 3, Funny
      > If you are programming on Widows ...

      I'd say if you're programming on widows, you need to find a way to replace the defunct parent process by forking yourself into a parent... but this is impossible since the child process(es) will absolutely refuse to have their defunct parent re-forked by some other forker who's coming in from a different, unsafe, unprotected location. Thus threading in lightly, and establishing shared values with the children whose parent has defuncted might be your only option of success when programming on widows...

      --
      'A lie if repeated often enough, becomes the truth.' - Goebbels
    9. Re:From the obvious dept by TekPolitik · · Score: 1

      there's no way for a thread to block on whichever happens first of a file descriptor being readable or a condition variable being signalled

      This is not quite true - you can always use a pipe, for example, to select and write a byte to the write side of the pipe when the condition variable is changed.

    10. Re:From the obvious dept by totally+bogus+dude · · Score: 1

      Doubt it since java threads will use the threading library of the OS the VM is running on.

      Welcome to the world of portable, multi-platform code!

    11. Re:From the obvious dept by scotch · · Score: 2, Insightful

      Java threads only work on one platfrom, the Java platform.

      --
      XML causes global warming.
    12. Re:From the obvious dept by MobyTurbo · · Score: 1

      Windows threads work on BOTH platforms, Windows XP/Vista and Windows CE. No, truly portable programs are when it compiles under *both* System V and BSD.
  8. Re:better yet by DelawareBoy · · Score: 2, Interesting

    Both are on the Intel Website, so it would appear, if any $$$ was paid at all, it would have been Intel both times. Since Intel doesn't write operating systems, they really don't care which threading model succeeds.

  9. Eeew, threads. by vadim_t · · Score: 2, Informative

    Here's the one thing Windows needs: fork()

    Threads have all sorts of nasty issues and pitfalls on any platform. Meanwhile, fork() is beautifully simple, and fork + socketpair lacks pretty much all of them. The speed may be a bit lower, but there's the great benefit of simpler and much safer code.

    1. Re:Eeew, threads. by Cheesey · · Score: 3, Informative

      On Windows, there is a much higher penalty associated with spawning a child process than on Unix. This makes using threads much more attractive - they are faster.

      I don't know why the Windows equivalent of fork() is slower than the Unix fork(). Perhaps it is a historical thing. Unix programs often use fork() - shell scripts use it all the time (this is one reason why a Python or Perl script is often faster). I'm just guessing now, but perhaps Unix fork() is efficient because it is frequently used and has therefore been optimised in various ways (e.g. memory is only copied if there is a write on Linux). Whereas on Windows, those optimisations are not necessary.

      --
      >north
      You're an immobile computer, remember?
    2. Re:Eeew, threads. by daVinci1980 · · Score: 4, Insightful

      These solutions are not equivalent. And the reason that fork/exec doesn't have the same problems as threading is because it can only (realistically) solve a subset of the problems that multithreading can solve.

      You have to consider the task you're working on before you decide whether you want to go with fork/exec or multiple threads.

      A sibling post mentioned the cost of creating new processes on windows, and that's definitely something to consider: it's quite expensive to do so on windows.

      However, the more important question is the problem you're working on solving.

      If you're working on a task that allows each drone to work without communicating with any of the other drones, then fork/exec is a possible candidate. If you're working on an application where you require even a minimal amount of synchronization between different drones, fork/exec is a huge, huge pain in the ass.

      An example of a good fork/exec app: webserver. One process deals with hearing the incoming connection, spawns off a new process to actually handle an individual connection. As a bonus, a single bad client connection will most likely NOT kill the whole webserver. (A malicious client will kill the process they've connected to, but probably none of the other processes, unless they manage to hang a database, etc).

      An example of a good multithreaded app: anything that plays lots of sounds (for a specific example, a game). There's lots of synchronization that has to go on here: threads have to be started (or more likely pulled from a pool) to play a sound, the threads playing the sound have to check back periodically to see if they should stop playing (or need to adjust their volume or other processing effects), they need to notify the originating thread when they have completed, etc. No one in their right mind would use fork/exec for this. Besides the high overhead of the process spawn on windows, you would need a process for each of the sounds playing, and you would need to use the OS interprocess communication apis to synchronize between the different processes (shared memory, global mutexes, or file pipes). Note that file pipes aren't sufficient for synchronization, so you'd still have to use OS mutexes to sync on.

      Yup.

      --
      I currently have no clever signature witicism to add here.
    3. Re:Eeew, threads. by multipartmixed · · Score: 2, Interesting

      > (e.g. memory is only copied if there is a write on Linux)

      Not just Linux.

      I think this was the case with SVR4 and BSD4.3.

      But that was a LONG time ago... memory gets fuzzy..

      It's entirely probable that the first time I read about fork being copy-on-write was in Tannenbaum's yellow book, so it might even be in Minix.

      It has certainly been the case as far as I'm aware in every non-toy Unix and UNIX for at least a decade.

      But then again, I don't care, since I'm not a kernel developer. :)

      --

      Do daemons dream of electric sleep()?
    4. Re:Eeew, threads. by Jonny_eh · · Score: 2, Insightful

      Just an FYI, fork isn't always available. The best example I can think of is uClinux, a linux distro for embedded computers. With an MMU, a process cannot be copied, therefore, only threads can be used. This can be a pain in the butt sometimes, but luckily pthreads aren't so bad once you know how to avoid races and deadlocks.

    5. Re:Eeew, threads. by TheRaven64 · · Score: 2, Interesting

      Fork() is a hold over from a very long time ago. The very old machines did not have protected memory, and so each context switch meant dumping the contents of memory and loading a new process image. If you did a fork(), you just had to do the dump, but not the reload and you got a copy of the parent process's address space for free. Now, there are lots of hacks to try to make it fast (e.g. copy-on-write and vfork()). We keep using it because that's how UNIX has always worked, not because it's actually sensible.

      --
      I am TheRaven on Soylent News
    6. Re:Eeew, threads. by Viol8 · · Score: 1

      You can use shared memory between processes in the same way that you'd use shared global/static variables between threads , so in that sense its fairly simple. Though of course you'd have to use some sort of signalling mechnism on top or just a polling loop on the memory (very wasteful). BUT , if you have an VERY complicated application its usually best to leave threads alone as they in my experience at best double the complexity of the program and at worst ,well , its anyones guess - I've spent literally days trying to find race condition bugs with threads and its not funny.

    7. Re:Eeew, threads. by vadim_t · · Score: 1

      threads have to be started (or more likely pulled from a pool) to play a sound,

      Threads have to be started too, and can also be pooled. So about the same in both cases.

      the threads playing the sound have to check back periodically to see if they should stop

      The parent process can simply send a signal (like SIGTERM). On startup the process can be told whether to stop abruptly, fade out, etc.

      Also, aborting a thread is not very nice, in C# for instance it will throw an Exception at some random point of the code. In comparison, a SIGTERM will invoke a handler, set a variable, and then the code can deal with it wherever comfortable.

      playing (or need to adjust their volume or other processing effects),

      This is more complicated, granted. But so it is with threads.

      they need to notify the originating thread when they have completed, etc.

      SIGCHLD

    8. Re:Eeew, threads. by 644bd346996 · · Score: 1

      uClinux does have a fork() on the platforms that do have an MMU, such as x86 and some ARM.

    9. Re:Eeew, threads. by mrsbrisby · · Score: 2, Insightful

      On Windows, there is a much higher penalty associated with spawning a child process than on Unix. This makes using threads much more attractive - they are faster.
      No, it doesn't mean threads are faster, it really just means Window's CreateProcess()+setjmp()+longjmp() slower and uglier than fork().

      Windows threads and pthreads are functionally equivalent, and for some metrics in some circumstances, the actual implementations might be better at some tasks versus others. In general, a program written for pthreads ported to windows will be slower on windows for plenty enough other reasons, that it is difficult to say exactly which threaded system is "faster".

      I don't know why the Windows equivalent of fork() is slower than the Unix fork().
      Because Windows doesn't have an equivalent of fork(). It has a CreateProcessEx() which is like a fork()+exec() -- one of the common uses of fork, but by no means the only use (nor the one parent is talking about).

      ... perhaps Unix fork() is efficient because it is frequently used and has therefore been optimised in various ways (e.g. memory is only copied if there is a write on Linux). Whereas on Windows, those optimisations are not necessary.
      No, it's that Windows developers think differently: Unix people think the Windows way of thinking is wrong. Windows developers think the Unix way of thinking is wrong (or "unnecessary").

      fork() means data isn't shared. This means that you don't need complicated locking structures, semaphores, etc. This also means that you know what channels need auditing for security, and which channels need extending to increase parallelism (scale).

      No matter how careful you are, threads never make auditing easier and they never make an application scale better (well, not significantly better).

      This isn't to say threads don't solve some problems, it is to say that they don't solve the same problems as fork(), and I hope at this point it goes without saying that threads are not a "more efficient fork()".
    10. Re:Eeew, threads. by EvanED · · Score: 1

      I don't know why the Windows equivalent of fork() is slower than the Unix fork(). Perhaps it is a historical thing.

      I don't know the technical reasons, but NT inherits a lot of design principles from VMS, where process creation was also a heavy operation.

    11. Re:Eeew, threads. by mrsbrisby · · Score: 1

      Just an FYI, fork isn't always available. The best example I can think of is uClinux, a linux distro for embedded computers. With an MMU, a process cannot be copied, therefore, only threads can be used.
      On an embedded system, threads will always decrease your performance. You should be using a different development model.
    12. Re:Eeew, threads. by Mysticalfruit · · Score: 5, Interesting

      A while back I had to write a server that would recieve concurrent network connections from different clients and then get some data from those clients and do some processing and then interact with a database, then when it's done the fork exits.

      I ended up writing the whole thing using forks and no pthreads. My code was then subjected to a code review and one of the questions that came up in the review meeting was why I used fork and didn't do the implementation in pthreads. My arguement was one of complexity. I was challenged with the "fork is old technology, you should have used pthreads" and my response was "My implementation is easy to understand, oh and by the way, it works!"

      Needless to say, my code has been in production for about a year and a half with no issues. I'm sure someone smarter than me could have wrote the whole using pthreads, but I'm just not sure what it would have gained them other than a slightly smaller memory footprint but at the price of increased complexity.

      --
      Yes Francis, the world has gone crazy.
    13. Re:Eeew, threads. by yo_tuco · · Score: 1

      "I don't know the technical reasons, but NT inherits a lot of design principles from VMS..."

      I don't know either but this extract from Wikipedia on Windows NT may shed some light:

      "Microsoft hired a group of developers from Digital Equipment Corporation led by Dave Cutler to build Windows NT, and many elements of the design reflect earlier DEC experience with Cutler's VMS and RSX-11."

    14. Re:Eeew, threads. by EvanED · · Score: 3, Interesting

      Maybe it originated like that, but the fork/exec model of starting a new process has another really big benefit as compared to, say, Windows's CreateProcesses, which is that it's easier to control the execution environment of the child process.

      Running as root and want to start the process with lower privileges? Do fork - setuid - exec. Want to open pipes to the child? Do pipe - fork - a couple calls in the child to connect the pipes to stdin/out - exec.

      By contrast, Windows has to encapsulate anything you want to be able to do to set up the child's environment in the CreateProcess call. That's why it takes 9 arguments, one of which is a flags argument where there are 15 flags, and one of which is a pointer to a struct with 17 fields (one of which takes another 9 flags).

    15. Re:Eeew, threads. by pthisis · · Score: 2, Informative

      Windows does have a copy-on-write process creation mechanism--use ZwCreateProcess or NtCreateProcess with a NULL SectionHandle. It wasn't in Win98 and earlier, and it's poorly documented, which means a lot of Windows programmers don't use it and threads get massively overused.

      But threads are rarely the right choice; OS developers spent years implementing protected memory for good reasons, and throwing it out even within the bounds of one process is rarely beneficial. If you need to share a ton of complex data structures that can't easily be allocated in shared memory, then threads are worthy of consideration; in practically every other case, multiple process solutions will wind up being easier to implement and maintain, and more stable.

      Threads look seductively easy at the outset, but you actually have to do a lot of bean counting to get things right; with multiple processes, you have to explicitly set up IPC which makes it _look_ more complex but in reality makes it very clear what the shared resources are. Finding any synchronization problems usually winds up being a lot easier in multiple process systems, and there are the obvious stability and security benefits.

      And depending on the task, multiple process solutions may actually be faster since when 2 process are running on seperate CPUs there's no need to worry about cache coherency, etc between them unless they're actually hitting shared resources.

      But the performance differences tend to be negligible in practice for many applications; benchmark and see before assuming.

      --
      rage, rage against the dying of the light
    16. Re:Eeew, threads. by cloudmaster · · Score: 1

      That silly old System V IPC couldn't possibly be used for allowing forked processes to communicate - everyone has to use threads. And who cares that Linux's fork implementation takes about the same overhead as creation of a new thread - fork is old. Yay new stuff!

    17. Re:Eeew, threads. by Kashif+Shaikh · · Score: 3, Informative

      You had no issues because a) performance was good enough and b) the rate of incoming client requests was relatively small compared to a loaded webserver. Now if you had thousands of client requests-per-second, the fork will show why-you-should-not-use-it-in-such-situations. In such cases you can use a pool of forked processes or simply write the whole damn thing using threads. For example, apache gives you the ability to change 'worker' modules...and you can experiment with that to get an idea of all these request processors. btw, threads don't complicate your code as long as you minimize data-sharing between threads and write the thread the same way as you were writing a forked process, except that you put all global variables within the thread's local data area. Kashif

    18. Re:Eeew, threads. by finity · · Score: 1
      Up until a few years ago, I think Apache only used forks or some equivalent to handle user requests. I think there was a lot of demand for it to become threaded, and now it is. Yours is a good example.

      And I second the fact that threads don't necessarily make it more complex. I think C++ lends itself to threaded applications very nicely. I was forced to learn about threading by trying to understand several pieces of software where the developers made many of the objects handle their own threading. The solution made a lot of sense for those problems. As I had never seen it before, it was difficult to understand at first, but I think it made the code cleaner overall. Anyway, I'm a EE so what do I know ;-)

    19. Re:Eeew, threads. by olau · · Score: 1

      You could also have used a kit for event-based programming and you wouldn't have to deal with multiprogramming at all. It can help a lot. If, of course, the things you were interfacing with wouldn't make it too difficult.

    20. Re:Eeew, threads. by FooBarWidget · · Score: 2, Interesting

      On the contrary, fork() is still sensible even today. Especially the copy-on-write implementations. fork() is ideal for saving memory in scripting languages.
      Imagine a Perl program, which requires about 35 MB of memory (25 MB for the parsed code, 10 MB for actual work). The user wants to run 6 instances of the program. Without fork (that is, on Windows) the user will need 210 MB of memory. On Unix I can use fork() and the user will only need about 100 MB of memory because the parsed code is shared between instances.
      This is not a hypothetical situation, I actually have a program that fits this description. A GNOME developer also recently developed a Python script which preloads PyGTK and forks instances, to save memory in PyGTK apps.

      fork() is also ideal for making a "protected copy" of your program. Suppose that you have a web server which forks when a new client connected. If the child process crashes then it won't affect the parent process or the other children. I don't think you can do that in Windows easily.

    21. Re:Eeew, threads. by pthisis · · Score: 4, Informative

      I don't know why the Windows equivalent of fork() is slower than the Unix fork(). Perhaps it is a historical thing. Unix programs often use fork() - shell scripts use it all the time (this is one reason why a Python or Perl script is often faster). I'm just guessing now, but perhaps Unix fork() is efficient because it is frequently used and has therefore been optimised in various ways (e.g. memory is only copied if there is a write on Linux).


      I already got modded down for mentioning it elsethread (not sure why), but Windows does have ZwCreateProcess and NtCreateProcess. Both of those will do a copy-on-write fork() style process creation if you pass them a NULL SectionHandle--it is much more efficient than the normal CreateProcessEx and is the way to go for doing heavy multiprocess stuff on Win32.

      see, e.g., http://www.osronline.com/showThread.cfm?link=35916
      --
      rage, rage against the dying of the light
    22. Re:Eeew, threads. by statusbar · · Score: 1
      fork is easier and safer for "low" usage servers. threads seem easier but can be ultra tricky to debug. The "best" way is harder but great for high usage servers....

      See The C10K problem

      --jeffk++

      --
      ipv6 is my vpn
    23. Re:Eeew, threads. by chengiz · · Score: 1

      Another example usage for multithreaded is in parallel processing, where lwps take advantage of multicore or other shared memory type architectures.

    24. Re:Eeew, threads. by k8to · · Score: 1

      Well you could go pure event handling/message passing or something. There are other approaches to code execution interleaving.

      Certainly some kind of threading/processes is the far and away most popular, familiar though. So I expect most projects to use that.

      --
      -josh
    25. Re:Eeew, threads. by dbIII · · Score: 1

      That's true - fork is da bomb.

    26. Re:Eeew, threads. by nconway · · Score: 1

      Imagine a Perl program, which requires about 35 MB of memory (25 MB for the parsed code, 10 MB for actual work). The user wants to run 6 instances of the program. Without fork (that is, on Windows) the user will need 210 MB of memory.


      Not true: the code section of any DLLs required by each instance of the program will only be loaded once.
    27. Re:Eeew, threads. by FooBarWidget · · Score: 1

      It's a *Perl* program, not a native program. The memory as used by the Perl parse tree is not shared between instances. The memory used by the Perl interpreter itself and related native libraries are tiny compared to the memory used by the Perl program itself.

    28. Re:Eeew, threads. by nconway · · Score: 1

      Well, the point is just that the total memory usage is not a simple product, as you had suggested. As for the relative size of the Perl DLL code sections against the total memory consumption of the process, I wouldn't say the DLLs are "tiny". For example:



      % size /usr/lib/libperl.so.5.8
            text data bss dec hex filename
      1246792 23876 8328 1278996 138414 /usr/lib/libperl.so.5.8



      (I don't have a Windows box handy, but DLLs should only differ to a relatively small degree.) For many small Perl programs, I'd expect the total size of the code sections of all the shared objects used could be a pretty significant portion of the process's total memory consumption.

    29. Re:Eeew, threads. by mrsbrisby · · Score: 1

      You had no issues because a) performance was good enough
      If performance is good enough, then you're done. Why would you bother wasting money and time working when the software is done?

      b) the rate of incoming client requests was relatively small compared to a loaded webserver.
      How do you know this? He didn't say he was talking about webservers, and he didn't say his load was small. I wrote several forking nameservers that handle tens of thousands of requests per second, and threads would only introduce cache contention and only slow it down.

      Now if you had thousands of client requests-per-second, the fork will show why-you-should-not-use-it-in-such-situations.
      No, it'll mean he can simply buy more computers. fork() means no data is shared; he can run his server on multiple machines and get load balancing for nearly free.

      For example, apache gives you the ability to change 'worker' modules...and you can experiment with that to get an idea of all these request processors.
      Apache is bad engineering. Nobody said he had to fork when the request came in. He could increase parallelism cheaply by simply forking off a thousand children, and having them all block in accept(). If Apache didn't crap all over the heap, it wouldn't waste megabytes per process.

      btw, threads don't complicate your code as long as you minimize data-sharing between threads and write the thread the same way as you were writing a forked process, except that you put all global variables within the thread's local data area. Kashif
      Did you ever think that the reasons threads don't complicate your code is that it had already achieved maximum complexity?

      Threads don't have local data areas. Several implementations of threading packages have thread-local arenas, but we're not talking about implementations of threading packages, we're talking about good engineering.

      Threads are a policy of share-everything. this means more code to audit, more code to check, more places for things to go wrong. Processes are a policy of share-nothing. Share-nothing gives you an awful lot of cool things for free (like scalability).

      The startup of fork() is rarely the bottleneck- you bring up Apache which is an excellent example. Apache isn't any faster when threaded. You want a fast webserver? Try and-httpd. It uses fork() and beats the crap out of Apache even when using a threaded mpm. It even outruns IIS. It wins because it's better designed.
    30. Re:Eeew, threads. by mrsbrisby · · Score: 1

      Embedded systems have to support multitasking. It just isn't practical to have one CPU per application in most cases. So all embedded OS's support threads.
      Threads aren't the only way to multiprogram. Coroutines and cooperative multitasking are both excellent ways to avoid rapid context switches- one for intra-task communication, and one for inter-task communcation.

      You really should read Knuth.
  10. Win32thread vs PosixThread by burni · · Score: 1

    Which one is better ?

    Perhaps it´s the same discussion that language A is better than language B ?

    perhaps it´s the same answer, the one that you prefer and fits your style.

    You will find posix implementations on much more plattforms, so if you want to write portable
    code, you should know you shouldn´t try win32thread ;)

    so if somebody of the operating Buzzwordfollowers heared "Linux" and now prays "Linux", ,you should have used Posix ;)

    1. Re:Win32thread vs PosixThread by DulcetTone · · Score: 1

      I have to believe your use of those "improved" apostrophes is an intentional funny.

      tone

      --
      tone
    2. Re:Win32thread vs PosixThread by Luxifer · · Score: 1

      This must have been written by the same guy that submitted the "EMI &mdash Ditching DRM is Going To Cost You" thread. Man, that guy sure gets around.

  11. win32 has 1 thing i want pthreads to have by musikit · · Score: 2, Informative

    i have had to do a lot of porting from win32 to linux/bsd/mac lately and maybe i just cant find it in the documentation anywhere but 1 function i would really appreciate the pthread team adding is

    pthread_join_with_timeout() the equivilent of the win32 WaitForSingleObject

    often i set a flag for a thread to end and it might have already been completed. i want to be able to join immediately if it's already completed and if it isn't process some other event and try to join again.

    i can program around this however it would be extremely nice addition to pthreads.

    1. Re:win32 has 1 thing i want pthreads to have by Steendor · · Score: 2, Insightful

      Obviously it's not a required featuer, but perhaps it just wasn't deemed to be a useful feature.

      The few times I've written multi-threaded programs, I had no reason to join completed threads at the earliest possible moment. One use I can think of would be to recycle threads to process a queue. In that case, wouldn't it be better to divide the recycling management and the processing into separate threads?

    2. Re:win32 has 1 thing i want pthreads to have by tjw · · Score: 4, Informative


      I'm not an expert on pthreads by any means, but I think what you're looking for is pthread_cond_timedwait().

      --

      XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UB E-TEST-EMAIL*C.34X
    3. Re:win32 has 1 thing i want pthreads to have by awol · · Score: 1

      Yeah, I know the feeling. We have an abstraction layer that does this goodness although even then not generically. The tradeoff in my view is true shared memory, and the pain that comes from the absence of that in Windows probably outweighs the goodness of WaitForSingleObject.

      Interestingly, Linux has a call; semtimedop which works for semaphores

      --
      "The first thing to do when you find yourself in a hole is stop digging."
    4. Re:win32 has 1 thing i want pthreads to have by dominator · · Score: 4, Informative

      pthread_cond_timedwait() waits on a condition variable, which basically signals that a mutex has been released. Win32 calls these things "events". It is not the same thing as joining on a thread. Joining a thread means "I'm waiting for this thread to exit, so that I can capture its return value."

      Sure, you could implement something like pthread_join_with_timeout() using a conditional inside the thread. But you'd need to do that manually, as pthreads doesn't provide a primitive for that particular use-case AFAIK.

    5. Re:win32 has 1 thing i want pthreads to have by softcoder · · Score: 2, Insightful

      Not to disparage your legitimate concern. You are porting an existing app, and you would like analogous features in the target. However this is a bit like saying Linux will not be ready for the desktop until it can exactly emulate [fill in proprietary product here.] in spite of the fact that there may be equivalent but not identical capability provided.
      Perhaps the development model for pThreads is different than the Windows one, and the call you want is not as useful if you are starting out from that model.

    6. Re:win32 has 1 thing i want pthreads to have by boa · · Score: 3, Informative

      >Sure, you could implement something like pthread_join_with_timeout() using a conditional inside the thread. But you'd need to do that manually, as
      > pthreads doesn't provide a primitive for that particular use-case AFAIK.

      A quick look in pthread.h tells me that there's one function named pthread_timedjoin_np. The function seems to be a GNU extension and the _np suffix is short for not portable. It probably does that the OP wants, but may not be portable enough for his needs.

      HTH
      boa

    7. Re:win32 has 1 thing i want pthreads to have by Anonymous Coward · · Score: 1, Interesting

      Joining to get the return value of a thread is pretty much a broken programming style on POSIX. Joins are only really used to recover resources. You should use some other mechanism to find out when a thread "terminates" (like condition variables) and use the pthread_join just to clean up the resources of the terminated thread.

      Detached threads avoid this issue, and is the solution adopted by Mozilla for their cross-platform threading needs. It means you can't just return from a thread sensibly, but they make the conscious choice not to rely on this behavior.

      While I'm sure the Windows way is convenient in some sense, I don't find the POSIX model deficient in any sense. Thread cancellation is a related issue as to why waiting for threads to exit is somewhat silly. Threads should signal when they've completed work, and you should be watching/waiting for this, not simply joining on threads waiting for them to terminate.

      It's even easy enough to build a data type/procedure to do all this for you in just a few steps.

    8. Re:win32 has 1 thing i want pthreads to have by oso · · Score: 1

      I agree. Join with timeout would be very nice for proper process cleanup and termination. You can simulate it 98% with timed cond wait, but this isn't atomic and requires complicated upper layer logic.

      In other words, it's better or print out "Thread failed to terminate" than to simply hang forever :-)

  12. Not the first such arguement by Anonymous Coward · · Score: 1, Insightful

    "Taste Great" "Less Filling"
    "Fruity Pebbles" "Cocoa Pebbles"
    "Chocolate" "Peanut Butter"
    "Duck Season" "Rabbit Season"

    1. Re:Not the first such arguement by ericski · · Score: 1

      Doesn't matter as long as it gets me drunk.
      No to either.
      Yes to both.
      Duck Season. Definately Duck Season.

    2. Re:Not the first such arguement by borroff · · Score: 1

      You forgot "Frankenberry" and "Count Chocula".

      Not to mention "Booberry".

    3. Re:Not the first such arguement by Sloppy · · Score: 1

      Rabbit season!

      --
      As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
  13. I see nothing wrong or contradictory here. by mmell · · Score: 1

    Aren't most *NIX users (and especially Perl-geeks) fond of saying that there's more than one way to get the job done? I'd say the only difference here is choosing the right tool for the right job.

  14. PThreads is better by swm · · Score: 4, Informative

    The articles read like one of those English assignments where you have to pick an issue and then write two essays, one supporting each side. Probably the author wrote them to generate traffic to his websites, or maybe for freelance fees.

    Anyway, PThreads is better. The reason is that Win32 gives you a fixed set of synchronization primitives. If you can solve your problem with those primitives. they work great. If you can't, you are completely stuck.

    For example, it used to be that a socket handle was not a synchronization object, so you couldn't integrate select() calls with other synchronization primitives. Maybe that's been fixed, but if it isn't sockets, it will be something else.

    PThreads gives you condition variables. They are harder to program, but once you understand them, you can use them to synchronize on absolutely anything. You aren't dependent on the OS to have foreseen your special needs and provided special synchronization primitives to meet them.

    If you really want the Win32 model, it is easy enough to build it on top of PThreads, but there is no way to build PThreads on top of Win32.

    The complaint about lost signals in PThreads means that the author is using them incorrectly.

    1. Re:PThreads is better by leuk_he · · Score: 4, Informative

      there is a pthreads implementation build on top if win32. I am not saying it is efficient, but it does the job.

    2. Re:PThreads is better by complexmath · · Score: 2, Interesting

      If you really want the Win32 model, it is easy enough to build it on top of PThreads, but there is no way to build PThreads on top of Win32.

      Not strictly true. It is possible to build condition variables for Windows (Windows has Semaphores after all, which can be used to make just about anything), but the Windows threading model makes doing so far from easy. Please note that I'm not defending WinThreads, however, so much as clarifying this particular issue.

    3. Re:PThreads is better by PhrostyMcByte · · Score: 5, Informative

      You're in luck-

      Vista comes with APIs for condition variables and reader-writer locks so you don't have to spend 15 minutes writing your own.

    4. Re:PThreads is better by fitten · · Score: 3, Interesting

      I've programmed in both and, other than the fact that you can't use sockets in the Wait... APIs (as you mention - but the BSD socket code is layered on top of native Win32, so you'd be passing objects created by two different subsystems to one subsystem's call, which shouldn't be expected to work), the rest of your post is either lack of experience with Win32 threads or subjective preference on your part.

      Personally, I've found situations using each API where the functionality desired was very difficult to replicate in the other API. It usually requires some rethinking, is all. And, last I checked, there were things you could do in either API that weren't easily reproducable in the other API.

      However, both APIs tend to evolve towards each other over time so it becomes less of an issue.

    5. Re:PThreads is better by mitch0 · · Score: 1

      For example, it used to be that a socket handle was not a synchronization object, so you couldn't integrate select() calls with other synchronization primitives. Maybe that's been fixed, but if it isn't sockets, it will be something else.

      PThreads gives you condition variables. They are harder to program, but once you understand them, you can use them to synchronize on absolutely anything. You aren't dependent on the OS to have foreseen your special needs and provided special synchronization primitives to meet them. This seems to imply that you can syncronize on condition variables and sockets at the same time. I've wrote some threaded server in pthreads some years ago, and I faced the same problem (I needed to wait on either a condition to happen or a socket selector to wake up) and I ended up using a socketpair() between the master and slave threads instead of a condition variable 'cos I couldn't wait on both at the same time. Has something changed in that regard, or I misunderstood you there?

      thanks,
      mitch
      --
      // "If human beings don't keep exercising their lips,
      // their brains start working." -- Ford Prefect
    6. Re:PThreads is better by dmayle · · Score: 4, Interesting

      It's not so cut and dry. I use a library I wrote to abstract away PThreads and Win32 Threads to give me a multi-platform interface, but I would say that each side has their upsides and downsides.

      With pthreads, there's no way to combine socket i/o and thread notification. In Win32, I can have a thread waiting on both a socket and an event at the same time, allowing me to cleanly signal I/O blocked threads. This isn't the case with pthreads.

      However, Win32 REALLY needs a way to handle negative mutexes (ie. taking more than one resource from a mutex at a time). I had to write my own, and it was a serious pain to make sure I didn't have any race conditions. All the articles I've seen on Win32 equivalents had race conditions, and that means that there means that there are probably developers trusting multi-threading primitives that they really shouldn't be./p>

    7. Re:PThreads is better by MythoBeast · · Score: 4, Insightful

      Vista comes with APIs for condition variables and reader-writer locks so you don't have to spend 15 minutes writing your own.

      Well, fifteen minutes writing, plus ten years of programming experience to be sure that you aren't going to create a deadlock in some obscure circumstance.

      --
      Wake up - the future is arriving faster than you think.
    8. Re:PThreads is better by Twylite · · Score: 4, Interesting

      You are talking mostly bollocks, probably because you don't program using the Windows API

      Anyway, PThreads is better. The reason is that Win32 gives you a fixed set of synchronization primitives. If you can solve your problem with those primitives. they work great. If you can't, you are completely stuck.

      And PThreads also gives you a fixed set of primitives. In some respects they are more powerful, in others they are weaker. This is a bullshit strawman.

      For example, it used to be that a socket handle was not a synchronization object, so you couldn't integrate select() calls with other synchronization primitives.

      WTF?

      1. select() has nothing to do with synchronization. Although it does have something to do with scheduling.
      2. select() can't wait on "synchronization primitives" under *nix. Really. Try man select . It works with FDs, only.
      3. select() is not a core function of the Windows API. It is part of Winsock, which uses lower level scheduling primitives.
      4. Finally, if you want to do asynchronous development with Windows you use Async IO, not select. Async IO is built on top of Events, which are synchronization primitives.

      That brings me to the next point: in Unix there is no wait to wait on multiple synchronization primitives (as opposed to FDs) at once, and only a few primitives support a timed wait. In Windows you have WaitForMultipleObjectsEx. Look it up.

      Let me be clear on the difference: in Windows the scheduler API for waiting on IO and synchronization primitives is fully integrated - you can wait on any combination of IO and sync objects in the same Wait call. You must of course be using Windows Async IO which uses Events rather than FDs as the waitable object. Under *nix you can wait for multiple condition variables, or multiple file descriptors, or a single mutex / thread / process. There is no way to link an FD to a condition variable.

      PThreads gives you condition variables. They are harder to program, but once you understand them, you can use them to synchronize on absolutely anything. You aren't dependent on the OS to have foreseen your special needs and provided special synchronization primitives to meet them.

      In Windows you have Mutexes, Events and Semaphores. Events alone are sufficient to provide almost identical functionality to condition variables. You may have missed that memo.

      I say "almost identical" because the underlying scheduler behaviour is slightly different, which makes it very difficult to perfectly emulate Pthreads on Win32. Read Strategies for Implementing POSIX Condition Variables on Win32.

      If you really want the Win32 model, it is easy enough to build it on top of PThreads, but there is no way to build PThreads on top of Win32.

      Cough. Bullshit. Cough. Read Porting of Win32 API WaitFor to Solaris Platform to get a clue. It is possible to build Pthreads on top of Win32, and vice versa. Neither emulation is particularly efficient though.

      The complaint about lost signals in PThreads means that the author is using them incorrectly.

      The complaint about weakness in the Win32 scheduling API means that the author is using it incorrectly.

      --
      i-name =twylite [http://public.xdi.org/=twylite], see idcommons.net
    9. Re:PThreads is better by dmayle · · Score: 2, Informative

      As my comment is mounting in score, I just realized that I said negative mutexes when I meant negative semaphores. Of course you can't have a negative mutex, a mutex is just for mutual exclusion. It's a semaphore that has a count associated with it.

      Sorry for the typo...

    10. Re:PThreads is better by dedazo · · Score: 1

      The reason is that Win32 gives you a fixed set of synchronization primitives

      Someone else already covered most of the reasons you're wrong on this, but I'll just add one more: I/O completion ports.

      --
      Web2.0: I love when people Flickr my cuil and digg my boingboing until my google is reddit and I start to yahoo
    11. Re:PThreads is better by CAIMLAS · · Score: 1

      I'd hardly consider that 'luck' - more like 'yuck'. It's like saying, "hey, you can sell your 2002 Ford Taurus and get this Yugo - it has a CD player now!"

      --
      ~/ssh slashdot.org ssh: connect to host slashdot.org port 22: too many beers
    12. Re:PThreads is better by gooser23 · · Score: 2, Informative

      You may not be able to use sockets directly with WaitFor[Single|Multiple]Objects(s), but you can attach an event to a socket (using WSAEventSelect IIRC) and wait on that, along with other things (which effectively gives you BSD's select() for Windows' file handles.

      As far as the discussion on concurrent programming goes, I'm surprised no one has yet mentioned boost.threads.

      --
      "Dying tickles!" -- Ralph Wiggum
    13. Re:PThreads is better by Anonymous Coward · · Score: 1, Funny

      You're saying you typoed "semaphores" as "mutexes"? Wow, that's a hell of a finger-slip. Anyway, fuck you. Oops, sorry about that typo, I meant "take care."

    14. Re:PThreads is better by Twylite · · Score: 3, Insightful

      From the great grandparent:

      If you really want the Win32 model, it is easy enough to build it on top of PThreads

      From me (the grandparent):

      Cough. Bullshit. Cough. Read Porting of Win32 API WaitFor to Solaris Platform [sun.com] to get a clue.

      It is not easy to build the Win32 model on Pthreads. The WaitForMultipleObjects emulation is a complete hack that pretty much re-implements the Win32 scheduler in userland. Even then it doesn't support a number of synchronization objects that Win32 can (e.g. threads, so that you can wait for thread termination). And it won't work properly unless the underlying *nix scheduler displays round-robin characteristics (anything with historical scheduling will cause a Producer-Consumer arrangement that works perfectly on Win32 to display massive latency on *nix).

      The Solaris WaitFor described in that document works only with Event objects. You can't wait on anything other than events like you can in Win32, and you can't link Solaris file IO states (i.e. readable or writable) to those emulated events.

      So you can't construct an instruction like "Wait for socket X to be readable OR event QUIT to be signalled", which is quite possible in Windows. In fact you can't do that at all on any *nix system that I am aware of (not even with kqueue or dev/poll to my knowledge). Instead you loop checking QUIT then doing a select()/poll() X with a timeout.

      --
      i-name =twylite [http://public.xdi.org/=twylite], see idcommons.net
    15. Re:PThreads is better by dmayle · · Score: 1

      If you take the producer/consumer metaphor of the semaphore, we consider a thread blocked as being a consumer, and a thread that does the signaling as a consumer. It's easy to imagine each consumer as wanting a resource, and so when multiple consumers want a resource, they each wait with the semaphore blocked at zero.

      What happens if one thread wants multiple resources? They have to take resources one at a time until the available count is zero, and then continue waiting one at a time as resources come in. Assuming ten threads, nine waiting for one resource at a time, and the other waiting for ten resources, at each incoming resource, the heavy user will have a 1/10 chance of receiving a resource, needing almost 100 resources to be supplied before it can work. That's a possible interpretation, but not very fair for the larger user. The heavier the load, the worse the inbalance.

      If however, we support negative semaphores (like with pthreads' semop system call), the heavy user will set the value of the semaphore to a negative value, and incoming resources will go to increasing the semaphore until it hits zero. At zero, the first incoming resource has an equal chance of being distributed among all of the waiting threads, meaning that in the above case, on a first come first serve system, only 19 resources are needed to satisfy all ten threads as opposed to the 100 or so resources necessary to give everyone a turn under the Win32 model.

      Of course, you have to be careful of a heavy user starving the light users, but in pthreads, you have the choice between the two models (with IPC_NOWAIT in the semaphore flag). With Win32, I was forced to write a negative semaphore using a system semaphore and a system mutex (which itself could have been served if pthread condition variables existed on Win32!).

      But, like I said above, Win32 pthreads doesn't have the ability to combine I/O and thread synchronization. The best you can do is go the other way, use a pipe as your synchronization primitive and combine that with the socket (as mentioned by someone else above), but that doesn't have some of the conveniences of synchronization primitives (for example, a semaphore has a resource limit, allowing duplicate signals to be effectively discarded.)

    16. Re:PThreads is better by sted · · Score: 1

      Vista comes with APIs for condition variables and reader-writer locks so you don't have to spend 15 minutes writing your own. You are not a frequent reader of comp.programming.threads, aren't you?
    17. Re:PThreads is better by SanityInAnarchy · · Score: 1

      Reading these articles and the comments here, it would seem that wine has a much better chance of being efficient than cygwin ever will, simply because UNIX APIs tend to be sensibly lower level. So, cygwin is a bit like trying to implement, say, C or C++ on top of C#. You could do it, but it would be much more efficient to build C# on top of C or C++, and, in fact, we do (Mono is written in C++, if I remember right).

      --
      Don't thank God, thank a doctor!
    18. Re:PThreads is better by abdulla · · Score: 1

      That brings me to the next point: in Unix there is no wait to wait on multiple synchronization primitives (as opposed to FDs) at once, and only a few primitives support a timed wait. In Windows you have WaitForMultipleObjectsEx. Look it up.
      You can use a barrier under pthreads. Look it up.

      Let me be clear on the difference: in Windows the scheduler API for waiting on IO and synchronization primitives is fully integrated - you can wait on any combination of IO and sync objects in the same Wait call. You must of course be using Windows Async IO which uses Events rather than FDs as the waitable object.
      Under *nix you'd use AIO. It may not be integrated directly with the synchronisation primitives, but that's what makes it beautiful, a clear separation of API and behaviour.
    19. Re:PThreads is better by DraconPern · · Score: 1

      IPC_WAIT = WaitForSingleObject with a 1 millisec timeout?

    20. Re:PThreads is better by ingenthr · · Score: 1

      You really should look at Solaris Event Port Completion. It may not have everything you're looking for, but it should help. It does a good job of bridging what exists in Unix while adding a lot of functionality.

      The referenced sun.com documents are quite old, and don't include anything in modern Solaris and OpenSolaris derived OSs.

    21. Re:PThreads is better by julesh · · Score: 1
      For example, it used to be that a socket handle was not a synchronization object, so you couldn't integrate select() calls with other synchronization primitives. Maybe that's been fixed, but if it isn't sockets, it will be something else.

      Asynchronous Notification Using Event Objects

      [...] The WSAEventSelect function behaves exactly like the WSAAsyncSelect function. However, instead of causing a Windows message to be sent on the occurrence of an FD_XXX network event (for example, FD_READ and FD_WRITE), an application-designated event object is set. [...]


      WSAEventSelect has been available since NT 3.51 / Win95. Are you sure you know what you're talking about? What "something else" do you mean, because I've never encountered anything I can't synchronise on in Windows.

      PThreads gives you condition variables. They are harder to program, but once you understand them, you can use them to synchronize on absolutely anything. You aren't dependent on the OS to have foreseen your special needs and provided special synchronization primitives to meet them.

      Please explain to me how (without creating an additional thread, something I could do equally in any OS) I can use a condition variable to catch an event that isn't specifically supported.

      If you really want the Win32 model, it is easy enough to build it on top of PThreads, but there is no way to build PThreads on top of Win32.

      Which is presumably how come there are no pthread implementations available on windows.
    22. Re:PThreads is better by julesh · · Score: 1

      Vista comes with APIs for condition variables and reader-writer locks so you don't have to spend 15 minutes writing your own.

      Well, fifteen minutes writing, plus ten years of programming experience to be sure that you aren't going to create a deadlock in some obscure circumstance.


      Or, you know, typical undergraduate-level education in concurrent programming best-practice for avoiding such issues.

  15. Both and Neither by FellowConspirator · · Score: 1, Informative

    It's not that difficult. POSIX' value is in its portability. Win32's value is in the fact that it's the native model.

    Generally speaking, the native model will always offer superior performance and a superset of the features of POSIX threads. Be that Win32, Solaris, Linux, or what have you -- it's a good rule of thumb that the native threading model and API performs better and is more flexible.

    That said, the difference is generally small enough that it's eclipsed by the portability feature if portability will ever be a concern. The fact that the programmer can learn a single threading API and use it anywhere means more flexibility in development and finding developers, and generally higher code quality (since people that have a skill focus on multi-threaded programming are almost assuredly well-versed in the POSIX API).

    1. Re:Both and Neither by __aapopf3474 · · Score: 1

      Neither. See: "The Problem with Threads," Edward A. Lee, EECS Department, University of California, Berkeley, Technical Report No. UCB/EECS-2006-1, January 10, 2006.

    2. Re:Both and Neither by Hal_Porter · · Score: 1

      Not really, Win32 is a very thin wrapper in this case. All the Win32 thread functions have identical equivalents in the native API. E.g. CreateThread becomes NtCreateThread. And NtCreateThread is just a syscall into the kernel.

      http://www13.informatik.tu-muenchen.de/lehre/prakt ika/SS02/bsprakt/inside_the_native_api.html

      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
  16. Point of view by mcvos · · Score: 1

    If you keep the two articles next to each other, you get a nice comparison of the advantages and disadvantages of each approach. Pthreads are apparently more elegant and easier to understand, but also more strict, while win32 threads are more lenient when you're not quite sure what's going on. In pthreads, there's only one way to start as new thread, in win32 there's more than one way. Undoubtedly each with its own advantages, but you do have to know the difference. As for persistence of signals, there's apparently two ways to do it, again each with its own advantages and disadvantages.

    They both have one major disadvantage, though: They're different from the other, which undoubtedly makes it harder to port some code.

    1. Re:Point of view by geekoid · · Score: 1

      The articles in question are 3 years apart. Things change in 3 years.

      Port? aha. I have had to write code that can be compiled in either enviroment.
      Same code. Actually it had to cimpile in Solaris, Linux and Win32.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    2. Re:Point of view by StarvingSE · · Score: 1

      Pthreads are hard to deal with, but programming can be made easier using something such as the OpenMP API.

      --
      I got nothin'
  17. "An anonymous reader"? by kievit · · Score: 1

    I bet that "anonymous reader" is actually Clay Breshears himself.

  18. Simple Answer: by sqlrob · · Score: 1

    What will net the most /. hits?

    1. Re:Simple Answer: by caluml · · Score: 1

      If thee casteth two opposing nets, thee will catcheth at least some fish.

      - Me, 2007.

  19. It's quite simple, really by 0xdeadbeef · · Score: 3, Funny

    One uses lowercase and underscores. The other uses studlycaps and Hungarian notation. It is an aesthetic choice.

    1. Re:It's quite simple, really by peterpi · · Score: 1

      So obviously pthreads is the winner by a knockout... Right?

      Tell me I'm NotTheOnlyOneWho finds_this_more_readable :(

  20. Re:Yes, the real world is a complicated place. by Ctrl-Z · · Score: 5, Insightful

    It is perfectly feasable for there to be ways in which Win32 threads are better than Pthreads (as hard as that is to believe), and also vice versa. Hence the two articles. You didn't read the two articles, did you?

    From the first one:

    I've used both POSIX threads (Pthreads) and Win32 threads APIs and I believe that Pthreads has the better programming model of the two. While each threading method can create threads, destroy threads, and coordinate interactions between threads, the reason I make this claim is the simplicity of use and elegance of design of Pthreads. Let me illustrate with a few examples. And, from the second one:

    I've used both POSIX threads (Pthreads) and Windows threads APIs, and I believe that Windows has the better programming model of the two. While each threading method can create threads, destroy threads, and coordinate interactions between threads, the reason I make this claim is the simplicity of use and elegance of design of the Windows threads API. This is all from the perspective of multithreaded code developers or maintainers. Let me illustrate with a few examples.
    --
    www.timcoleman.com is a total waste of your time. Never go there.
  21. Clone by RAMMS+EIN · · Score: 1

    I don't know how win32 threads work, but I do know that I would like my thread system to have an interface like fork(), so both the original and the new thread continue from that point onward. This would unify threads with continuations, allowing interesting and powerful programming techniques. POSIX threads don't work that way, but Linux's clone() can, or so the manpage leads me to believe.

    --
    Please correct me if I got my facts wrong.
    1. Re:Clone by multipartmixed · · Score: 1
      If you can re-write your forkish program from the form

      while()
        if (!fork())
        {
          blah;
          blah;
          blah;
        }
      to

      doWork(args)
      {
        blah;
        blah;
        blah;
      }
       
      while()
        if (!fork())
          doWork(args);
      Then you can do what you want with a wrapper oriented around pthread_create() and friends so that your code will look like

      while()
        magicFunc(doWork, args)
      with trivial complexity.
      --

      Do daemons dream of electric sleep()?
    2. Re:Clone by RAMMS+EIN · · Score: 1

      You have found the reason why threads are not typically used as much on *nix as on Windows. on Windows, spawning a new process is expensive (or used to be). On *nix, forking a new process is cheap. Programming with processes is much easier than programming with threads (fewer ways to shoot the same foot), and thus, threads are usually preferred on *nix. Also, you can get the benefit of shared memory (which threads provide) by using (BSD, SysV, or POSIX) shared memory.

      On the other hand, first-class functions and multiple levels of lexical scoping, as well as referential transparency (common in many programming languages besides C) make multi-threaded programming a lot easier.

      --
      Please correct me if I got my facts wrong.
  22. there are differences, but not _that_ many by radarsat1 · · Score: 4, Interesting

    The thing is, they are just APIs. They both do just about the same thing. Asking which one is better is a pretty pointless question. I have always thought that the WaitFor* functions in Windows are quite nice, but frankly not that much of an advantage. It's quite rare that you actually need to wait for multiple objects of different types at the same time. Combine that with the fact that its semantics are slightly different for different objects (it destroys a thread, but only unlocks a mutex), and your program is that much more difficult to read. Of course, this is just comparing two APIs, a mostly pointless exercise, and says _nothing_ about implementation, which is quite a bit more important in terms of comparison. For example, Linux has completely changed its pthreads implementation since the switch from 2.4 to 2.6 (from LinuxThreads to NPTL), and programmers get the advantages without needing to change anything. In Windows, of course, we have no (or very little) idea of the implementation, except for what we can infer from the API, and performance tests. A third argument in this little debate could be to argue that one should just stay away from threads, period. I haven't successfully done it myself, since I find the threading paradigm useful, but using processes and non-blocking IO properly, one can avoid threads completely. Of course that's a bit easier to do with some of the Posix functions (eg. socketpair). But doing so will probably result in a more robust piece of software, and which scales better to multiple cores/processors. (Because processes do not share memory, so inter-thread cache misses will be minimized.)

    That said, I find it quite creepy that this guy wrote these two articles with extremely similar wording for his introductions, making the exact opposite points. It is very strange. I wonder what his motivation was.

    1. Re:there are differences, but not _that_ many by KingEomer · · Score: 1

      Could you explain the point about how processes not sharing memory will minimize inter-thread cache-misses? Are inter-thread cache misses somehow worse than inter-process cache misses. Wouldn't the fact that processes don't implicitly share memory cause more overall cache misses?

      I'm not an expert on this, so I'm probably wrong. Regardless, I don't quite understand it, so I wouldn't mind having it explained.

      Thanks!

    2. Re:there are differences, but not _that_ many by Kashif+Shaikh · · Score: 1

      Exactly -- they are just APIs. Fan-boys get into stupid flame-wars about what API is better. Real guys would talk about implementation of pthreads under linux vs winthreads. Heck, the linux NPTL implementation got reader/writer locks, spinlocks, and a lot better performance compared to the sucky LinuxThreads. For example, grabbing a lock on a mutex is just a couple of instructions (if no one is holding the lock), and thread context switch time is 1us.

      But if ppl just resort to comparing APIs, it like saying "mine is bigger than yours" :)

      kashif

    3. Re:there are differences, but not _that_ many by ScrewMaster · · Score: 1

      But if ppl just resort to comparing APIs, it like saying "mine is bigger than yours" :)

      Indeed ... but what happens if mine really is bigger than yours?

      --
      The higher the technology, the sharper that two-edged sword.
  23. Is this a joke ? by CmdrGravy · · Score: 3, Informative

    Is this some kind of weird joke ?

    First of all on it's own terms the story makes no sense, the anonymous coward starts off by saying it's interesting when people disagree. He then links to two articles which, as he points out, are written by the same person and then asks who is right. He has just pointed out the opinions are both from the same person and he wants to know who is right, this is just moronic.

    Secondly although I know nothing about PThreads or Win threads I can see that both those articles are largely the same with just the terms PThreads and Win threads switched so in one article he is claiming an advantage for one based on what he has stated as the advantages of the other in his other article.

    Why is this on the front page, why was the submission accepted in the first place when it's complete nonsense and the most recent post by the author of both articles was in 2006.

    1. Re:Is this a joke ? by PseudoQuant · · Score: 1

      Haven't you heard? Due to the Energy Policy Act of 2005, April fools day has been moved 5 weeks earlier, with "mod following" conventions, putting it on the next valid business day. Today is officially "April fools day". Have at it!

    2. Re:Is this a joke ? by Secret+Rabbit · · Score: 1

      """
      First of all on it's own terms the story makes no sense, the anonymous coward starts off by saying it's interesting when people disagree. He then links to two articles which, as he points out, are written by the same person and then asks who is right. He has just pointed out the opinions are both from the same person and he wants to know who is right, this is just moronic.
      """

      It's only stupid if you didn't read this part "metaphorically speaking?". Please actually read before you post.

      """
      Secondly although I know nothing about PThreads or Win threads I can see that both those articles are largely the same with just the terms PThreads and Win threads switched so in one article he is claiming an advantage for one based on what he has stated as the advantages of the other in his other article.

      Why is this on the front page, why was the submission accepted in the first place when it's complete nonsense and the most recent post by the author of both articles was in 2006.
      """

      It's about starting a discussion. It doesn't matter that they are basically the same article, nor does it matter that they were written by the same person. These articles are a starting point for us to discuss something, which as it happens, goes on a fair bit around here.

      Honestly, is this your first day? Or did you just have a neural misfire?

      But, to contribute to the discussion a bit, since when I program I want to have the code as cross-platform as possible, I go with pthreads. They run pretty much everywhere (including windows: http://sourceware.org/pthreads-win32/) whereas win32 threads only run on, *gasp*, windows. But, that's just my opinion.

    3. Re:Is this a joke ? by mrchaotica · · Score: 1

      This is why everyone reads Slashdot for the discussion, not the articles -- I've actually learned a few things from reading other posts today.

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    4. Re:Is this a joke ? by CmdrGravy · · Score: 1

      The phrase "metaphorically speaking" in that context is simply meaningless, where is the metaphor ? Possibly the submitter meant to say "pretend the two articles I linked to weren't written by same person and that when I said at the beginning of the article that it's interesting when different people have different opinions but it's even more interesting when the same person has two contradictory opinions"

      I like a good discussion as much as the next person but if the submitter wanted to discuss the benefits and pitfalls of PThreads vs Windows threads surely he could have just said that and posted to some interesting articles on the subject which would have more authority than two articles written by the same person which look suspiciously similar with just the words Windows and PThreads swapped around.

      I think that posting things simply for purposes of creating a heated discussion is called flamebaiting which given the normal robust discussions which gone on in the threads here is really uncessary on the front page of /.

    5. Re:Is this a joke ? by ucblockhead · · Score: 1

      Because slashdot "editors" rarely read links submitted and aren't nearly as technical as they'd have you believe.

      --
      The cake is a pie
  24. WaitForMultipleObjects by zindorsky · · Score: 2, Insightful

    Like the author, I have programmed with both pthreads and the Win32 threading API. I like the design of the pthreads API better, but (as the author also points out), pthreads has no equivalent to WaitForMultipleObjects. Sometimes it is very convenient to be able to wait on many objects and be able to be signaled by any one of them. With pthreads there is no way to do this.

    Or am I missing something? Please someone, tell me how to wait on multiple objects (and be triggered by just one) with pthreads!

    --
    If the geiger counter does not click, the coffee, she is not thick.
    1. Re:WaitForMultipleObjects by Cheesey · · Score: 1

      Couldn't you use a semaphore for that? Get your producers to call sem_post when ready, and have your consumer call sem_wait. sem_wait will block until a producer calls sem_post. The relationship between calls to sem_post and calls to sem_wait is guaranteed to be 1:1.

      Did I misunderstand what you were trying to do?

      --
      >north
      You're an immobile computer, remember?
    2. Re:WaitForMultipleObjects by swm · · Score: 2, Insightful
      Let's see if I remember how to do this...

      mutex mx;
      condition_variable cv;
      int a, b, c, d;
      ----- one thread -----

      lock(mx);
      while (! (a || b || c || d)) wait(mx, cv);
      unlock(mx);
      ----- another thread ------

      lock(mx);
      a = 1;
      signal(cv);
      unlock(mx);
      ----- another thread ------

      lock(mx);
      b = 1;
      signal(cv);
      unlock(mx);
    3. Re:WaitForMultipleObjects by tricorn · · Score: 1

      Yes, but the problem with that is a thread that only wants to wait on "a || b" will get notified when c or d get kicked - sure, it goes right back to sleep, but that's needless overhead.

      Having the flexibility to use multiple condition variables with the same mutex is nice, but is also an easy way to shoot yourself if not used carefully. In Java, you have condition variables, but they are strictly one-to-one with a mutex. Doing a reader-writer lock is much easier with the pthreads style of condition variables, for example.

    4. Re:WaitForMultipleObjects by abdulla · · Score: 1

      Please someone, tell me how to wait on multiple objects (and be triggered by just one) with pthreads!
      Use a barrier. I'm not sure what you mean by "triggered by just one", and I'm about to head off to work, so I hope that helps.
  25. Theads vs processes by Nicolay77 · · Score: 1

    AFAIR the windows theading model is better, because windows was designed with heavily multithreading in mind, and a very expensive operation of creation of new processes.

    In Linux is the other way around: forking a process is very efficient, so no one used threads so they were not as efficient as the ones in Windows.

    Of course both process creation in Windows and threading in Linux could have been perfected in all this years, but that is something I don't know.

    That said, a bug in a thread will bring the application or server down, and a bug in a forked process is trivial to correct: just restart the process.

    --
    We are Turing O-Machines. The Oracle is out there.
    1. Re:Theads vs processes by eklitzke · · Score: 1

      I'm not sure about Windows, but at least in Linux threading has been extremely efficient since LinuxThreads was replaced by NPTL (a few years ago). While LinuxThreads wasn't that performant, NPTL has very impressive benchmarking results, and is really a first class threading implementation.

      --
      #include ".signature"
  26. pthread is straightforward ? by herve_masson · · Score: 1

    Reading and understanding Pthreads code written by someone else is straightforward

    I have to disagree with TFA. I think pthread is the most bloated API I have ever used; it is truly amazing how they managed to turn simplicity into messy useless complexity. Back in the dec/osf ages, my boss gave me a 300 pages book on pthread so that I could get started (there were not many examples at this time). This book was almost entirely dedicated to decypher this API, not even focusing much on multithread programming concepts. Even if you want to provide complex stuff (as pthread clearly does), you don't need to make every user paying the hard price, that's part of what a good API is, if you ask me.

    Anyway, I think both are inadequate for direct use. I always write a small abstraction layer that fit my needs, and this layer is everything but concise on pthread, while it's quite small and elegant on windows. For once, windows API is properly designed, and that's rare enough to be said.

    1. Re:pthread is straightforward ? by Anonymous Coward · · Score: 2, Interesting

      I think pthread is the most bloated API I have ever used;
      I think this has to be a bit of an overstatement, don't you think?

      If you think the pthread API is "bloated", or unintuitive for simple tasks, I'm going to have to go ahead and say you're a troll.

      Bloated? On a Linux box I happen to have handy, libpthread.a is 208Kb.

      Hard to use for simple tasks? Perhaps all of the *_init() functions are a bit daunting to the eyes. But does the Wikipedia article's example really look that bad?

      I first used the pthread interface when I was only 15 years old. Even though I didn't fully understand the consequences of parallelization back then, I didn't feel like the library itself was enourmously comlex. I was able to whip out multi-threaded socket programs pretty quickly. Later I used Win32 threads. I found it to be basically the same.

      I'm surprised more of the people complaining about the lack of WaitForMultipleObjectsEx() haven't mentioned POSIX semaphores. I saw one post about them, that's it.
  27. Re:Yes, the real world is a complicated place. by aled · · Score: 1

    It is perfectly feasable for there to be ways in which Win32 threads are better than Pthreads (as hard as that is to believe), and also vice versa. Hence the two articles.

    Often you will find reasons to choose one thing, and other reasons to choose something else, life it tricky that way. When I was looking for a house, one was huge with lots of rooms, but out of town, and one was smaller, but so close to work.


    This is Slashdot, post only binary answers to any questions or prepare yourself to flamed.

    Example:
    Question: what is the meaning of life?
    Valid answers: true or false.

    Mmmh... maybe nerds are programmed in Prolog
    --

    "I think this line is mostly filler"
  28. Re:better yet by burk3 · · Score: 3, Funny

    So one might say that intel goes both ways?

  29. A better Win32/Linux thread article by NullProg · · Score: 4, Informative

    It sounds like the developer from Intel needs to ask IBM:

    http://www-128.ibm.com/developerworks/linux/librar y/l-ipc2lin1.html

    Enjoy,

    --
    It's just the normal noises in here.
  30. Win32 threads are better by springbox · · Score: 1

    You can do the same things with both of them, but Win32 threads are less of a pain in the ass to work with.

  31. And when you don't know what's going on, STOP by postbigbang · · Score: 1

    If you don't have a handle on the state machine, don't go further and hope that child processes through a fork or a thread spawn are going to inherit the conditions you want. This is a weak argument for spawning Win32 threads.

    When compiling, the actions taken to get to assembler/machine code are far different between Win and Posix. Posix has a wonderful elegance and a brevity of code, but Win will take a much larger portion of the libs (depending on whose compiler you're using) to ensure it catches the state, which is inherently larger in Windows than most all *nixes. It might execute more cleanly (and there is no guarantee of this), but at the price of dragging enormous amounts of code with it. That extra code may also contain semaphores and constraints in unknown states, too, not to mention sensitive array boundary and cache management risks.

    --
    ---- Teach Peace. It's Cheaper Than War.
  32. Boring by deblau · · Score: 1

    Engineer discovers that there are pros and cons in deciding between two systems, but has to make a general value judgment. The world does not obey trichotomy, you know.

    --
    This post expresses my opinion, not that of my employer. And yes, IAAL.
    1. Re:Boring by SirTalon42 · · Score: 1

      RTFA. Massive parts of them were copy and pasted (the entire first paragraph is the same except 1 useless sentence is added at the end, and 'pthreads' is changed to 'win32 threads' near the end, then the middle section is pretty much the same as well with the reason for pthreads being better now being the reason why pthreads are worse.

      Maybe he did change his opinion between the two articles. If so, it'd be nice to know why he did, such as what opened his eyes, which would be REALLY informative (especially if it turned out to be a free laptop... *cough*).

  33. win32 equivalent for pthread_cond_wait? by edwinolson · · Score: 2, Interesting

    I seem to recall looking for--and not finding-- a win32 equivalent of pthread's condition variables. E.g., atomically release a mutex and then wait for an event. As the (excellent) pthread man page describes, this is a useful operation, often necessary to avoid a race condition.

    What is the right way to do a pthread_cond_wait under win32?

    1. Re:win32 equivalent for pthread_cond_wait? by yeremein · · Score: 1

      What is the right way to do a pthread_cond_wait under win32?

      Use the Boost Threads library. It's portable to many platforms (including Windows) and supports condition variables.
    2. Re:win32 equivalent for pthread_cond_wait? by 3dr · · Score: 1

      Boost's threading library is nicely done. One aspect of Boost I like are the various lock types. scoped_lock is great for placing in a code block and having it cleaned up properly:
      func()
      {
          blah;
          blah;
          {
              scoped_lock theLock(m);
              blah2;
              blah2;
          }
      }

      In some test code I needed time delays. Boost's types for measuring time are clumsy, but as I remember that is one area they are working to fix.

    3. Re:win32 equivalent for pthread_cond_wait? by Foolhardy · · Score: 1

      SignalObjectAndWait . A mutex is considered signaled when it is unowned; using a mutex as the object to signal will release the mutex (and then wait for the second object to become signaled atomically).

    4. Re:win32 equivalent for pthread_cond_wait? by loconet · · Score: 1
      --
      [alk]
  34. Re:quothe the poster-What Has Changed by Nom+du+Keyboard · · Score: 5, Insightful
    "or what has changed since the first article was written?"

    What has likely changed is were the paycheck came from this week.

    --
    "It's the height of ridiculousness to say for those 9 lines you get hundreds of millions."
  35. Personally,... by scriptedfate · · Score: 1

    ...I'd stick with uC++: http://plg.uwaterloo.ca/~usystem/uC++.html

    Use low-level constructs in low-level languages. If you're writing in a high-level language (like C++) you're doing so specifically to avoid things like pthreads. ...or because it's mandated by work/school.

  36. $ model by pato101 · · Score: 1

    not pretending to be very original, but:

    1) Say something
    2) wait
    3) Say the opposite
    4) not so "??"
    5) Profit!
    6) Sit and wait for the "get the facts" article based on 3)

    1. Re:$ model by Hal_Porter · · Score: 1

      Bloggers == http://en.wikipedia.org/wiki/Glenda_Slagg ? Whodathunkit????!

      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
  37. Re:I like threads. by multipartmixed · · Score: 1

    A lot senior programmers (myself included) run away from other people's threading code because there always seems to be one stupid, gotcha bug in whatever steaming pile of code we're handed that takes 168 hours longer than expected to find, and it's only found by old-school code-reading and note-taking, because the test case takes 12 hours to replacate.

    Now, *writing* MT code from scratch without using local-to-the-enterprise libraries? Nobody with any skills should be afraid of that. If you can't visualize your threads interacting in your head... you don't fully understand the problem domain and should promptly commit seppuku.

    --

    Do daemons dream of electric sleep()?
  38. Re:And so the point becomes... by skoaldipper · · Score: 5, Funny

    > Who gives a shit. They're just threads, man. Both work.

    You know, I said this very same thing back in the 70s. However, my buddy with the bell bottoms and KISS shirt got more play than I ever did with my adidas shorts and Vader cape.

    --
    I hope, when they die, cartoon characters have to answer for their sins.
  39. Opinion by Anonymous Coward · · Score: 2, Funny

    "It's interesting when different people have different opinions."

    No it is not.

  40. Re:better yet by ultranova · · Score: 2, Interesting

    Since Intel doesn't write operating systems, they really don't care which threading model succeeds.

    Except that Win32 threading model only works on X86 (since it needs Win32, which only runs on X86), while Pthreads work everywhere. Pthreads therefore mean more competition for Intel, since the program using them can be made portable.

    --

    Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  41. Dr Jykle & Mr. Hyde by the100rabh · · Score: 1

    hmmmm.... I dont know if its a case of MPD (Multiple personality disorder)

  42. MSFT POSIX by tyler_larson · · Score: 2, Interesting

    Here's the one thing Windows needs: fork()

    Windows has fork(), as well as all the other POSIX calls.

    Originally, Windows NT had 4 separate APIs: the NT API, Win32, POSIX, and OS/2. The NT API was (and still is) the one used by the kernel. It has all the capabilities necessary to support the other three, and is never (well, rarely at least) used directly by applications. Win32 was, at the time, very new and hadn't seen wide use--it was designed as the primary API for Windows 95, and Microsoft wasn't yet sure whether it would catch on in the NT world.

    The other two APIs have the same level of explicit support in the kernel as Win32, but there's a catch: you have to pick which subsystem you want to use for a given application. Win32 programs can't make calls to the POSIX subsystem, nor vice-versa. Over time, it became clear that only Win32 was being used for NT programming, and the other two APIs disappeared. The OS/2 API is, as far as I know, completely unavailable for modern versions of NT (i.e. 2000, XP, and Vista), while the POSIX API is still supported, but isn't available by default.

    Check out Windows Services for Unix. This packages installs (and uses) the NT POSIX API.

    For more information, read Microsoft Windows Internals

    --
    "With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea...."
    RFC 1925
    1. Re:MSFT POSIX by julesh · · Score: 1

      Yes, windows supports multiple API's but the rest of the post is incorrect. Win16 was the API used in Windows 3.1.

      I don't see the parent contradicting this anywhere.

      Windows NT (First appeared in 1993) included Win32.

      Nor this; he does appear to be wrong in saying it was designed for Win95, although Win95 was being worked in '93, because most sources seem to agree Win95 was the result of a backport of Win32 on top of Windows 3. So, yes, Win32 was almost certainly designed for NT, not ported to it.

      The whole "NT" moniker was because of the microkernel architechture of the operating system.

      There are multiple, conflicting explanations of the NT name. None that I've heard relate to it being a microkernel. In fact, it isn't a microkernel -- it runs at least some of its drivers in kernel mode (and, I believe, always has done).

  43. Metaphorically Speaking? by JakusMinimus · · Score: 1

    So who is right (metaphorically speaking?), or what has changed since the first article was written? Did this make anyone else's head explode? Someone help me here, where is the metaphor?

    I have to agree with another poster that posited that this article's submitter is the same shill that wrote the blog entries.
    --

    You can be an atheist and still not want to succumb to some weird cross-over sheep disease -- AC
  44. A Diff view by HHacim · · Score: 2, Interesting

    I ran both articles through diff and here's what it looks like: 1c1 I've used both POSIX threads (Pthreads) and Windows threads APIs, and I believe that Windows has the better programming model of the two. While each threading method can create threads, destroy threads, and coordinate interactions between threads, the reason I make this claim is the simplicity of use and elegance of design of the Windows threads API. This is all from the perspective of multithreaded code developers or maintainers. Let me illustrate with a few examples. 3c3 Simplicity of data types. In Pthreads, each object has its own data type (pthread_t, pthread_mutex_t, pthread_cond_t, etc.) while, in Windows threads, there is pretty much just the one type: HANDLE. For Pthreads this means different functions are used for working with each object type. Reading and understanding Pthreads code written by someone else can be straightforward. However, this does mean that the programmer must know the number, order, and type of parameters for all the different functions. On the other hand, because of the use of the same type for different objects, there is a Create* function for each different object and a corresponding Release* function for most. 5c5 Perhaps the biggest advantage of a single object data type is that there is only the one function needed to make a thread block while waiting for an object: WaitForSingleObject. Thus, only one set of parameters needs to be known regardless of whether the code is waiting on a thread, a mutex, a semaphore, or an event. The related function, WaitForMultipleObjects, is just as simple to use and easily overcomes the problem of needing to wait for multiple thread terminations one function call at a time (pthread_join) that Pthreads requires. While some may say that using a single data type for many different objects can lead to confusion when used in WaitFor* calls, programmers should set the name of the handle such that it is readily apparent whether the code is expecting a thread termination, an event to be signaled, or a mutex to be released. 7c7 WaitForMultipleObjects functionality. Besides being able to block a thread waiting for multiple thread terminations in a single call, the programmer can actually wait for any out of a set of threads to terminate. That is, even when only one thread has completed, the WaitForMultipleObjects function can be set to return and indicate which thread triggered the return. If there is specific "clean up" processing that depends on the identity of the thread that finished, this can be done before returning to wait on the remaining threads. This clean up processing will be done in the most efficient order possible, soon after each thread terminates, no matter in what order this happens. Pthreads can perform similar post-processing, but will need to wait for the threads to terminate is some fixed order. So, even if the last thread finishes first, it must wait for all the post-processing of the previous threads to be completed. 9c9,15 Because different objects all use the HANDLE type, a call to WaitForMultipleObjects can be set to wait for any combination of threads, mutexes, semaphores, and/or events. This feature can give the programmer a flexibility that cannot be easily (if at all) duplicated in Pthreads. As an example, I've written Windows code that used an array to hold both thread and event handles to support a threaded search through data. The ideas was to signal the blocking thread if the item being looked for was found and when the searching thread terminated; if the object was not found, the searching thread terminated without setting the event. By waiting for either handle to cause WaitForMultipleObjects to return, a simple switch statement could determine if the item had been found (and process the data) plus perform some post-processing computation upon the termination of the searching thread (regardless of whether the search was successful). > > Persistence of signals. To paraphrase a classic conundrum in terms of Pthreads: If a thread signals a conditio

    1. Re:A Diff view by HHacim · · Score: 2, Interesting

      sorry the diff sould've looked like this:
      1c1
      I've used both POSIX threads (Pthreads) and Windows threads APIs, and I believe that Windows has the better programming model of the two. While each threading method can create threads, destroy threads, and coordinate interactions between threads, the reason I make this claim is the simplicity of use and elegance of design of the Windows threads API. This is all from the perspective of multithreaded code developers or maintainers. Let me illustrate with a few examples.
      3c3
      Simplicity of data types. In Pthreads, each object has its own data type (pthread_t, pthread_mutex_t, pthread_cond_t, etc.) while, in Windows threads, there is pretty much just the one type: HANDLE. For Pthreads this means different functions are used for working with each object type. Reading and understanding Pthreads code written by someone else can be straightforward. However, this does mean that the programmer must know the number, order, and type of parameters for all the different functions. On the other hand, because of the use of the same type for different objects, there is a Create* function for each different object and a corresponding Release* function for most.
      5c5
      Perhaps the biggest advantage of a single object data type is that there is only the one function needed to make a thread block while waiting for an object: WaitForSingleObject. Thus, only one set of parameters needs to be known regardless of whether the code is waiting on a thread, a mutex, a semaphore, or an event. The related function, WaitForMultipleObjects, is just as simple to use and easily overcomes the problem of needing to wait for multiple thread terminations one function call at a time (pthread_join) that Pthreads requires. While some may say that using a single data type for many different objects can lead to confusion when used in WaitFor* calls, programmers should set the name of the handle such that it is readily apparent whether the code is expecting a thread termination, an event to be signaled, or a mutex to be released.
      7c7
      WaitForMultipleObjects functionality. Besides being able to block a thread waiting for multiple thread terminations in a single call, the programmer can actually wait for any out of a set of threads to terminate. That is, even when only one thread has completed, the WaitForMultipleObjects function can be set to return and indicate which thread triggered the return. If there is specific "clean up" processing that depends on the identity of the thread that finished, this can be done before returning to wait on the remaining threads. This clean up processing will be done in the most efficient order possible, soon after each thread terminates, no matter in what order this happens. Pthreads can perform similar post-processing, but will need to wait for the threads to terminate is some fixed order. So, even if the last thread finishes first, it must wait for all the post-processing of the previous threads to be completed.
      9c9,15
      Because different objects all use the HANDLE type, a call to WaitForMultipleObjects can be set to wait for any combination of threads, mutexes, semaphores, and/or events. This feature can give the programmer a flexibility that cannot be easily (if at all) duplicated in Pthreads. As an example, I've written Windows code that used an array to hold both thread and event handles to support a threaded search through data. The ideas was to signal the blocking thread if the item being looked for was found and when the searching thread terminated; if the object was not found, the searching thread terminated without setting the event. By waiting for either handle to cause WaitForMultipleObjects to return, a simple switch statement could determine if the item had been found (and process the data) plus perform some post-processing computation upon the termination of the searching thread (regardless of whether the search was successful).
      >
      > Persistence of signals. To paraphrase a classic conundrum in terms of

  45. Re:I like threads. by Duhavid · · Score: 1

    Looking at the hot shot contractor's code after they blightly
    forge ahead can be amusing as well.

    I recall the work of a coworker in the multi-threaded realm,
    he wrote a function to do something, and it needed a mutex
    within it's bounds. That person locked very early in the
    function, and held the lock for a long ( in clock cycles )
    time. And that person had about 15 returns, each of which
    very carefully released the lock. We kept having problems
    which the log files kept telling us it was that function.
    And every time, I would review that function for problems,
    and aside from my dislike of the style, no problems would be
    found. Then I told my boss I was tired of reviewing that
    code each time this happened, I was going to rewrite it.
    Minimized the time the lock was held, one in, and one out
    ( and got rid of several subblocks of code that were identical ).
    No problems after that.

    What is my point? Some can't do it. Fewer can do it. Of those
    that can, not all do it well.

    --
    emt 377 emt 4
  46. Weird. But here's a rebuttal by bytesex · · Score: 1

    ]] in Windows threads, there is pretty much just the one type: HANDLE.

    Yes. A HANDLE in WIN32 can also be a window, a file, a thread, a mutex, a pipe, a process and your grandmother. Since when is type checking not a good thing.

    ]] there is only the one function needed to make a thread block while waiting for an object: WaitForSingleObject.

    Except, of course, if you're waiting for something to be posted to a pipe. Then you have to associate the pipe with a handle first. Oh and does he realize we have the same thing in UNIX ? It's called select() on a filedescriptor. Which you can't do in windows - because in windows, a pipe isn't a network socket isn't a filesystem object.

    ]] If a thread signals a condition variable and no other thread is waiting, does it make a sound?

    Why do you want to write crappy code ?

    Sorry - gotta go now. Diner's ready.

    Not mentioned: Why does windows create recursive mutexes by default ?

    Also not mentioned: Why doesn't UNIX have a proper POSIX event API that mixes with a threading API and a socket API ?

    --
    Religion is what happens when nature strikes and groupthink goes wrong.
  47. Re:why walking is better then driving by SirTalon42 · · Score: 1

    The problem isn't the change of opinion. The problem is the article is almost completely copy and pasted, as well as using the EXACT same reasons first why pthreads are better, and then in the newer one those reasons are why pthreads are worse. Now if the author pointed out his previous article (or just that he was originally a fan of pthreads) and explained why his opinion changed (such as what he learned between the 2 articles), THEN that would be an interesting read. But now both articles are just useless, since they use the exact same reasoning and logic, except with the opposite conclusion.

  48. Re:Moo by Chacham · · Score: 1

    Very true.

    I think SCO should see where they get here complaining that "Clay Breshears" is not a real person.

  49. Generic Synchronization Policies by ciaran.mchale · · Score: 1

    Both Win32 threads and POSIX Threads provide a low-level API that are many people find confusing. I have written a "Generic Synchronization Policies" (GSP) library that provides a higher-level abstraction that is much easier to use and has been ported to several threading packaged (Win32, POSIX, DCE, Solaris). I do not claim that GSP is a silver bullet but it is a significant step in the right direction. Interested readers can find the software and documentation (HTML, PDF, PowerPoint) at my web site: http://www.ciaranmchale.com/. The software and documentation are released under an MIT-style license.

  50. Writting is just a job, I doubt the author cares by ChrisA90278 · · Score: 1

    That the same guy would re-use his own words just goes to show you how useless most web article are. A witter is paid by the piece and will just bang out gibberish as long a he gets paid. I doubt these writers even have a real opinion. They are like lawers, they will argue either side. It's just a job.

    In real life which is best depends on your goal. Do you want your code to be tied to Windows or do you want it to be portable to other platforms?

  51. Plagarism by XenoPhage · · Score: 1

    So what rights does this guy have? Can he sue himself for plagarism? I mean there's definitely prior art there.. Personally, I think he stands to gain from this blatant rip off of his previous work.

    --
    XenoPhage
    Technological Musings
    1. Re:Plagarism by Tim+C · · Score: 1

      I know you're joking, but...

      Can he sue himself for plagarism?

      You sue for copyright infringement, not plagiarism. If he retains the copyright on the first article, he can do whatever he wants with it. If it was produced as a work for hire and someone else owns it (eg his employer at the time) then he may be liable, if they find out and object.

      I mean there's definitely prior art there

      Prior art is for patents, not copyright.

  52. he changed his mind in 3 years... by josepha48 · · Score: 1
    so what? He wrote the article saying pthreads was better in 2003, and then in 2006 he said win32 threads are better. He changed his mind. So?

    People who can't change their mind are called George Bushes and.. well look at the mess he got us into!

    --

    Only 'flamers' flame!
    Does slashdot hate my posts?

    1. Re:he changed his mind in 3 years... by hobbesx · · Score: 1
      Did you see the article differences? There's a post below yours that shows the diff output, you should check it out if you haven't already.

      People who can't change their mind are called George Bushes and.. well look at the mess he got us into!

      Quick! Someone get W. a copy of sed & awk...
      --
      This rating is Unfair ( ) ( ) Fair (*) Funny
      Sigh... If only. Modding would be so much more fun.
  53. wdiff output by cortana · · Score: 3, Informative

    Why [-Pthreads-] {+Windows Threads+} are better than [-Win32 threads-] {+POSIX Threads+}
    Clay Breshears
    [-2006-10-19-]
    {+2003-05-13+}

    I've used both POSIX threads (Pthreads) and [-Win32-] {+Windows+} threads [-APIs-] {+APIs,+} and I believe that [-Pthreads-] {+Windows+} has the better programming model of the two. While each threading method can create threads, destroy threads, and coordinate interactions between threads, the reason I make this claim is the simplicity of use and elegance of design of [-Pthreads.-] {+the Windows threads API. This is all from the perspective of multithreaded code developers or maintainers.+} Let me illustrate with a few examples.

    [-Separate-] {+Simplicity of+} data types. In Pthreads, each object has its own data type [-while-] {+(pthread_t, pthread_mutex_t, pthread_cond_t, etc.) while,+} in [-Win32 threads-] {+Windows threads,+} there is [-a mix of handles and separate types.-] {+pretty much just the one type: HANDLE.+} For Pthreads this means different functions are used for working with each object type. Reading and understanding Pthreads code written by someone else [-is straightforward-] {+can be straightforward. However, this does mean that the programmer must know the number, order,+} and [-less apt to lead to confusion.-] {+type of parameters for all the different functions.+} On the other hand, because of the use of the same type for different objects, [-when-] {+there is+} a [-Win32 program uses WaitForSingleObject, it may not-] {+Create* function for each different object and a corresponding Release* function for most.

    Perhaps the biggest advantage of a single object data type is that there is only the one function needed to make a thread block while waiting for an object: WaitForSingleObject. Thus, only one set of parameters needs to+} be {+known regardless of whether the code is waiting on a thread, a mutex, a semaphore, or an event. The related function, WaitForMultipleObjects, is just as simple to use and easily overcomes the problem of needing to wait for multiple thread terminations one function call at a time (pthread_join) that Pthreads requires. While some may say that using a single data type for many different objects can lead to confusion when used in WaitFor* calls, programmers should set the name of the handle such that it is+} readily apparent [-if-] {+whether+} the code is expecting a thread termination, an event to be signaled, or a mutex to be released. [-This also illustrates my next point.

    Unambiguous-] {+WaitForMultipleObjects+} functionality. [-I've-] {+Besides being able to block a thread waiting for multiple thread terminations in a single call, the programmer can+} actually [-seen Win32-] {+wait for any out of a set of threads to terminate. That is, even when only one thread has completed, the WaitForMultipleObjects function can be set to return and indicate which thread triggered the return. If there is specific "clean up" processing that depends on the identity of the thread that finished, this can be done before returning to wait on the remaining threads. This clean up processing will be done in the most efficient order possible, soon after each thread terminates, no matter in what order this happens. Pthreads can perform similar post-processing, but will need to wait for the threads to terminate is some fixed order. So, even if the last thread finishes first, it must wait for all the post-processing of the previous threads to be completed.

    Because different objects all use the HANDLE type, a call to WaitForMultipleObjects can be set to wait for any combination of threads, mutexes, semaphores, and/or events. This feature can give the programmer a flexibility that cannot be easily (if at all) duplicated in Pthreads. As an example, I've written Windows+} code that used an array to hold both thread and [-mutex handles, then wait on those-] {+event+} handles {+to support a threaded search through data. The ideas was to signal the blocking thread if the item being looked for was found+} and [-execute differen

  54. Re:I like threads. by DrWhizBang · · Score: 1

    ...when it come to programmers.

    Watchig some hot shot contractor panic when you aask them... ask if the nderstand ... ...
    The uderstand the definition...


    Dde, did one f them write the nput hndler for you keeyboard? I don't thin it works so sht ho.

    --
    Schrodinger's cat is either dead or really pissed off...
  55. The equals sign. by zonx+lebaam · · Score: 1

    There's a lot of languages out there, and the equals sign is a very popular symbol. In ML (which, like Lisp, is a functional language), '=' is used for both equality tests and assignment. On the procedural side, try Pascal (which used to be one of the most well-known languages). Equality is tested with '=' and assignment is indicated with ':='.

    1. Re:The equals sign. by Haeleth · · Score: 1

      In ML (which, like Lisp, is a functional language), '=' is used for both equality tests and assignment.
      To be pedantic, the assignment operators are ':=' and '<-' (depending on the dialect and the context).

      '=' is used for equality tests and binding, which is not quite the same thing as assignment. (To oversimplify greatly and also distort the truth somewhat, you can think of the expression "let foo = 1 in ..." as meaning "the equality test 'foo = 1' may be assumed to be true for ...")
  56. Re:better yet by YU+Nicks+NE+Way · · Score: 1

    Gosh, and here I was thinking that Windows CE -- which uses the Win32 threading model more heavily than any of the desktop OS's -- ran on all those other processors...silly me. That ARM chip in my phone must really be an x86.

  57. How about "none of the above"? by mad.frog · · Score: 1

    An interesting take on it from Brendan Eich:

    http://weblogs.mozillazine.org/roadmap/archives/20 07/02/threads_suck.html

    So my default answer to questions such as the one I got at last May's Ajax Experience, "When will you add threads to JavaScript?" is: "over your dead body!"

  58. A great multithreaded app! by dbdweeb · · Score: 1

    Here's a GREAT example of a multithreaded app... MySQL. Well done MySQL development team!!

  59. Submitter is nuts by trainsnpep · · Score: 3, Funny

    We have always been at war with Pthreads. We have never been at war with Windows threads.

    The submitter is clearly nuts. Everyone knows that we have always been at war with Windows threads. Anyone who suggests we're at war with Pthreads is insane.

    --
    --<Mike>--
  60. Slightly different design pattern is common: by Ayanami+Rei · · Score: 1

    http://users.actcom.co.il/~choo/lupg/tutorials/mul ti-thread/thread-pool-server.c

    Create your thread pool, have it wait for events on a queue, pull off and process, loop. If handled_requests > threshold, optionally kill + restart thread. (Implementation of that last bit left as user excercise)

    --
    THIS THING CAN TURN ON A DIME, MACROSSZERO STYLE ALSO FUCK BETA, ~NYORON
  61. Re:Q: What is the pthread version of select(...) by shani · · Score: 1
    The Linux man page for pthread_join() hints at the answer to your question:

    The pthread_join() function is a convenience that has proven useful in multi-threaded applications. It is true that a programmer could simulate this function if it were not provided by passing extra state as part of the argument to the start_routine(). The terminating thread would set a flag to indicate termination and broadcast a condition that is part of that state; a joining thread would wait on that condition variable. While such a technique would allow a thread to wait on more complex conditions (for example, waiting for multiple threads to terminate), waiting on individual thread termination is considered widely useful. Also, including the pthread_join() function in no way precludes a programmer from coding such complex waits. Thus, while not a primitive, including pthread_join() in this volume of IEEE Std 1003.1-2001 was considered valuable.
    Basically, roll your own.
  62. Do either compare favorably to OS/2 threads? :-) by Richard+Steiner · · Score: 1

    Just curious. OS/2 software tended to be heavily thread-oriented even back in the early 1990's, and many programs had a half-dozen active threads or more. It seems like neither Windows nor Linux has that kind of history, which is why programs like Firefox still seem stupid (to me) about spinning off background tasks for things.

    --
    Mainframe/UNIX Bit Twiddler and long time Windows/Linux Hobbyist.
    The Theorem Theorem: If If, Then Then.
  63. Obviously an experiment by tdelaney · · Score: 1

    The two posts simply take the same aspects for each, and reverse whether they're good or bad.

    I haven't read through the comments, but there are plenty. With this success, I suspect the original poster is now trying the experiment on Slashdot.

  64. Whoa, lots of paranoia here... by Al+Dimond · · Score: 1

    I read both articles in their entirity. It just sounds to me like the author wrote the articles as a pair, flipping his arguments around from one article to the other, to make a point: that the differences between the two threading models are simply differences, and that it's easy to apply opposite value judgements to each of them just by changing the wording of your description of a difference (most obvious example is the paragraph on signal persistence; compare how he amplifies and dismisses the difficulty of the same coding practices in each article). Or perhaps he was trying to help strong partisans recognize the viewpoints of people they disagreed with and come up with new approaches to their programming problems, or maybe he was trying to encourage developers to improve each threading model by recognizing the strenghts of others.

    To me that seems more likely than that he's a shill.

  65. Not String Theory but by PalmKiller · · Score: 1

    Seems to me that during the three years between the article he had a change of heart. I wonder if he is comparing old and slow linux pthreads instead of the newer nptl stuff in both cases?

  66. Threads by mlwmohawk · · Score: 1

    Can someone explain why this is news, I mean other than the fact that the guy is a moron.

    The implementation of threads on "UNIX" varies between BSD, unix, and Linux and each have their advantages/problems.
    Window's threading model has its advantages and drawbacks.

    Both threading systems spin off threads, and both platforms (assuming you can call UNIX a single platform) provide various mechanisms for synchronization and communication.

    There is almost nothing you can do with one API that you can't do with the other. It is more your pre-existing preference for one methodology over another that would dictate your API preference.

    I like pthreads better because I think there is a finer grain of control over how the thread executes.

  67. And memory footprint is a red herring. by Ayanami+Rei · · Score: 3, Insightful

    If you don't touch the heap, then not much is gained from pthreads over fork() in terms of memory usage. Code segments are shared, data is copy on write, and the stack is not shared in either case.

    --
    THIS THING CAN TURN ON A DIME, MACROSSZERO STYLE ALSO FUCK BETA, ~NYORON
  68. !Money, controversy by phonics · · Score: 1
    Well, not directly. Both were on Intel's site. It would seem that it was more an attempt to force controversy, both times. Especially the way it's ended:

    Windows:

    These are just some of the reasons that I think Windows threads is a better threading API than Pthreads. What do you think? Do you have other reasons to prefer Windows threads? Or do you think Pthreads is the better threading method? I'd like to hear about your preferences.


    pthreads:

    These are just some of the reasons that I think Pthreads is a better threading API than Win32 threads. What do you think? Do you have other reasons to prefer Pthreads? Or do you think Win32 threads is the better threading method? I'd like to hear about your preferences.


    This looks intentional to generate discussion. Does this "Clay" work for IBM? Is Clay trying to make the boards look active? Does Clay work for someone else? Is Clay trying to get someone else to do his/her (probably his, but i've learned not to assume) research?

    Does Clay get -1 FlameBait for this?
  69. Superficial differences. by SanityInAnarchy · · Score: 1

    As I understand it, Linux processes are lightweight enough that modern pthreads on Linux builds on top of fork/exec. Or something like that -- one is a wrapper for the other, I think.

    In any case, reading through your suggestions, the only real difference is that if you're writing in C (and thus vulnerable to buffer overflows), segfaulting a process won't bring down the entire app. One other difference is that fork/exec would tend to be easy to make distributed, as most of your communication would be in pipes. However, both of these ultimately come down to how the app is written, not what language or API you're using.

    So, the only real difference will be performance implications. On Windows, it's MUCH cheaper to spawn a thread than a process, and there is no fork, so on Windows, monolithic monstrosities are the only viable way to go.

    --
    Don't thank God, thank a doctor!
    1. Re:Superficial differences. by cortana · · Score: 1

      I think that fork and pthread_create are both wrappers around the clone system call.

  70. Re:Ninjas by Barny · · Score: 1

    Maybe they were ninja hippos?

    Oh come on, its 8am on a Tuesday, that's as good as its going to get aright?

    --
    ...
    /me sighs
  71. Weird by OrangeTide · · Score: 1

    This is the weirdest thing. Two articles by the same guy with nearly identical text proving the complete opposite. Perhaps the author has a sense of humor and he's playing a big joke on us, and he really feels there is no significant advantage or disadvantage over one threading API or another.

    The debate is pretty much irrelevant because you can't use Win32 threads on anything but Windows, and you can't use Pthreads on Win32 without problems. Different APIs for different domains.

    Pthreads is portable, but only if your OS is very similar to Unix (MacOS X, Solaris, Linux, QNX). The less like Unix you are, the worse Pthreads will work (either in performance or reliability). Try Pthreads on Win32 or vxWorks, it doesn't work as well as the native APIs.

    --
    “Common sense is not so common.” — Voltaire
  72. File pipes - unix sockets. by Ayanami+Rei · · Score: 1

    Unix sockets are excellent inter-process sync primitives. Coupled with the poll()/select() idiom you can create mailboxes for processes to send messages to each other, and depending on the OS implementation, you may get it with zero copies (or at most one), which is great.

    You can use this in conjunction with shared memory when you don't want any copies to occur, or when you want to implement many-reader, single-writer.

    And if that's not enough there's explicit POSIX IPC; not the greatest APIs but consistent in behavior across platforms. I mean it's good enough for Oracle...

    --
    THIS THING CAN TURN ON A DIME, MACROSSZERO STYLE ALSO FUCK BETA, ~NYORON
  73. Re:*HOAX* by 26199 · · Score: 1

    Congratulations on making the first insightful+relevant post!

    (To Slashdot, I mean. Not this article in particular.)

    Seriously, though, thanks for pointing that out...

  74. o rly? by Nykon · · Score: 1

    "It's interesting when different people have different opinions."

    No it isn't. Every person seems to have a different opinion about everything. Finding a person with a different opinion is about as interesting as finding out that there's porn on the internet.

    --
    "It's better to be a pirate then join the Navy"
  75. He responded. by MythMoth · · Score: 3, Informative
    --
    --- These are not words: wierd, genious, rediculous
  76. The differences aren't as important as the support by bored · · Score: 1

    I did win32 API coding at a previous job, at this one I use pthreads all the time.

    The real difference isn't so much in the basic thread library but what you can do once you have the thread. There are a LOT of gotchas with standard unix library calls in a threaded environment. When you start digging you discover all kinds of uglies when mixed with the API's that existed before pthreads. Things as simple as open/close are stunningly broken on many unix'es when mixed with threads. Far to many things in the basic API assume a single thread. When mixed with signals, async IO, DIO etc your world quickly starts to fall apart and you loose cross platform portability, and end up abstracting things away to just the functionality you need. At that point you might just as well use whatever native API's exist with object wrappers.

    Windows has its share of gotchas but the basic libraries work well with threads and provide everything you need without having to wonder how your going to get a thread safe version of getenv() (getenv_r() is not supported in glibc).

  77. Generalizing by hackwrench · · Score: 1

    So how would you suggest generalizing orders from a government to orders from a corporation?

  78. Or... by JourneyExpertApe · · Score: 1

    1) Write article about pthreads.
    2) Copy article, but change "pthreads" to "Win32 threads".
    3) Submit articles to /. anonymously.
    4) ???
    5) Profit!

    (Sorry, I was really starting to miss the Underpants Gnomes jokes. Does a cliche become less so if it hasn't been used for a while?)

    --
    If you can read this sig, you're too close.
  79. Nothing has changed by einhverfr · · Score: 4, Informative

    Read the two articles closely, and side by side. What you will see is that both articles have an identical structure and make simply the opposite cases. The opening is almost verbatim between the two articles, for example.

    Although there are three year between the articles and people change, this looks to me like someone trying to write different articles from different viewpoints rather than proving that one is best. If he really had changed his mind, maybe he would have said so and referenced his previous article rather than copying it?

    --

    LedgerSMB: Open source Accounting/ERP
    1. Re:Nothing has changed by Bacon+Bits · · Score: 1

      That was my reading, too.

      Honestly, the zeal of some slashdot readers is far in excess of reality. Anybody in IT or software engineering should be able to objectively evaluate *nix and Windows conventions without things turning into a political rant.

      --
      The road to tyranny has always been paved with claims of necessity.
  80. The answer, as usual is which one favors Linux, open source, Firefox and if none of the aforementioned fit, which ever one is less favorable for Microsoft.

  81. Actually, one of the articles... by mattis_f · · Score: 1

    addresses this.

    The two articles mentioned in the summary are only identical in the first paragraph - then he starts talking about WaitForSingleObject (in the older article) and WaitForMultipleObject (in the newer one). He also mentions how to accomplish the same thing in pthreads. I think.

    Didn't read it too closely, I was just looking for what the difference was. :-)

  82. Read beyond the first paragraph... by mattis_f · · Score: 2, Informative

    I was also fascinated by that ... but the articles actually diverge a bit later. The difference seems to be WaitForSingleObject in Win32 (in the older article, apparently it's not a good thing) which has been replaced by WaitForMultipleObject in the newer one (according to the author, a good thing).

  83. Indeterminancy by hackwrench · · Score: 1

    This is what Shrodinger's cat looks like before the waveform collapses, though once the superposition collapses, all statements made based on that superposition may collapse along with it.

  84. different conclusion? by happy_smile · · Score: 1

    I think the author just write on what's inside his mind, that's all. Except that might be the author have two personalities inside his mind? Let' see from both articles: A.In Pthreads, each object has its own data type (pthread_t, pthread_mutex_t, pthread_cond_t, etc.) while, in Windows threads, there is pretty much just the one type: HANDLE. B.In Pthreads, each object has its own data type while in Win32 threads there is a mix of handles and separate types. Which do you prefer? Pthread can be better than windows thread, windows thread can be better than Pthread. What's your great weakness? My great weakness is I don't have any weakness.

  85. Re:cache misses by KingEomer · · Score: 1

    Ah, thanks. I see now. The part about synchronizing caches between processors was what I needed to know.

  86. View complete thread for a possible clue by The+Empiricist · · Score: 1

    With a little bit of additional investigative work (I clicked on the button that said "View Complete Thread" under the pthreads better than Win32 threads posting), I discovered a post that may shed some light on Mr. Breshears' change of heart:

    ...There is, however, some things that win32 threads did better then posix threads. The WaitForMultipleObjects allows you to decouple the signaling and waiting threads better. In posix, if some thread wants to wait on multiple conditions, there has to be a condvar especially for that and the signaling thread has to know about it. In win32, the signaling thread only has to signal the events it knows about and not have to worry about other threads waiting for mulitple events, though there still the problem of events being lossey. Also win32 threads are more orthagonal. You do not have have totally different and incompatible signaling mechanisms like unix select/poll and pthread condvars. The kludges to make those work together are incredible....

    It appears that a posting my someone called Joe Seigh may have given Mr. Breshears another perspective to consider. That he was willing to change his position, rather than stretch to justify an original stance, shows some character that often is missing from those who publically express a point of view. I would not be surprised if we saw Mr. Breshears arguing sometime in the future that pthreads are better than Win32 threads---perhaps after pthreads have come out with some innovations that make them even more effective.

  87. Re:Do either compare favorably to OS/2 threads? :- by Richard+Steiner · · Score: 2, Insightful

    You seem to be somewhat misinformed. OS/2 and NT have pretty much the same heritage and hence why windows (NT) is VERY heavy into threads.

    Uh. No. Dave Cutler's rearchitected Windows NT kernel (from which all NT variants from 3.1 up to and including XP and probably also Vista are derived) has almost nothing in common with the 32-bit kernel that IBM completely rewrote for its OS/2 2.0 and later releases after the MS/IBM break-up.

    In fact, it's probably closer to VAX/VMS than it is to OS/2.

    Those two platforms' only common ancestry was the 16-bit OS/2 kernel, something both products shed 15+ years ago, and the only thing they had in common through NT 4 was the 16-bit VIO API that both of them supported (an old, outdated text-mode application interface even in the OS/2 world 15 years ago).

    If you've ever done performance comparisons of OS/2 2.x versus any NT flavor of similar vintage, you'd be quite aware that OS/2 has historically washed the floor with its distant Windows cousin on similar hardware on both single- and multi-CPU configurations. Remember the NT Server versus Warp Server review where a single Warp 3 server outperformed NT Server on a quad-CPU machine in both file- and print-serving benchmarks? There's a reason for that. NT possesses a slow architecture by design, and that is true from the kernel outwards.

    --
    Mainframe/UNIX Bit Twiddler and long time Windows/Linux Hobbyist.
    The Theorem Theorem: If If, Then Then.