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?"

91 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 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;
    4. 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.
    5. 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". ;)

    6. 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//

    7. 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?
    8. 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
    9. 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.
    10. 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.

    11. 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.

    12. 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.

    13. 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.

    14. 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.
  2. $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.
  3. 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 AmX · · Score: 2, Insightful

      Pascal?

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

      Visual basic. Or are we only counting real languages?

  4. 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 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."
    7. 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.

    8. 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
  5. 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 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.'"
    4. 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
    5. Re:From the obvious dept by scotch · · Score: 2, Insightful

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

      --
      XML causes global warming.
  6. 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.

  7. 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 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()".
    7. 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.
    8. 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).

    9. 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
    10. 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

    11. 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.

    12. 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
  8. 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 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.

    4. 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.

    5. 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

  9. 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 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>

    6. 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.
    7. 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
    8. 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...

    9. 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
    10. 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
  10. 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]

  11. 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.

  12. 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.
  13. 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.

  14. 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.

  15. 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 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);
  16. Re:better yet by burk3 · · Score: 3, Funny

    So one might say that intel goes both ways?

  17. 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.
  18. 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?

  19. 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."
  20. 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.
  21. 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.
  22. Opinion by Anonymous Coward · · Score: 2, Funny

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

    No it is not.

  23. 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.

  24. 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
  25. 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

  26. 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

  27. 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>--
  28. 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
  29. He responded. by MythMoth · · Score: 3, Informative
    --
    --- These are not words: wierd, genious, rediculous
  30. 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
  31. 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).

  32. 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.