Pthreads vs Win32 threads 385
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?"
So who is right (metaphorically speaking?), or what has changed since the first article was written?"
quothe the poster (Score:5, Insightful)
Vista's release and a massive advertising campaign/increase in revinue for microsoft partners?
$Money$ (Score:5, Insightful)
Who was paying for it.
Look at the dates, Dude. (Score:3, Insightful)
Not the first such arguement (Score:1, Insightful)
"Fruity Pebbles" "Cocoa Pebbles"
"Chocolate" "Peanut Butter"
"Duck Season" "Rabbit Season"
Re:Yes, the real world is a complicated place. (Score:5, Insightful)
From the first one:
Re:win32 has 1 thing i want pthreads to have (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?
WaitForMultipleObjects (Score:2, Insightful)
Or am I missing something? Please someone, tell me how to wait on multiple objects (and be triggered by just one) with pthreads!
Re:Look at the dates, Dude. (Score:5, Insightful)
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.
Re:Eeew, threads. (Score:5, Insightful)
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.
Re:Look at the dates, Dude. (Score:4, Insightful)
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.
Re:WaitForMultipleObjects (Score:3, Insightful)
Re:quothe the poster-What Has Changed (Score:5, Insightful)
What has likely changed is were the paycheck came from this week.
Re:Look at the dates, Dude. (Score:3, Insightful)
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.
Re:PThreads is better (Score:5, Insightful)
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.
Re:Eeew, threads. (Score:3, Insightful)
Re:Eeew, threads. (Score:3, Insightful)
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". 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). 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()".
Re:Pthreads = Win32 threads? (Score:2, Insightful)
Re:Pthreads = Win32 threads? (Score:1, Insightful)
Re:From the obvious dept (Score:2, Insightful)
Ummm... did you mean to say Java Threads?
Re:win32 has 1 thing i want pthreads to have (Score:2, Insightful)
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.
Re:Look at the dates, Dude. (Score:3, Insightful)
Re:quothe the poster (Score:2, Insightful)
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.
And memory footprint is a red herring. (Score:4, Insightful)
Re:PThreads is better (Score:4, Insightful)
From the great grandparent:
From me (the grandparent):
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.
Re:Look at the dates, Dude. (Score:3, Insightful)
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.
Re:From the obvious dept (Score:3, Insightful)
Re:quothe the poster (Score:4, Insightful)
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
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,
All of the enterprise
Re:quothe the poster (Score:2, Insightful)
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.
Re:Do either compare favorably to OS/2 threads? :- (Score:3, Insightful)
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.