|
I use worker threads to avoid blocking the GUI thread but that's about it.
If you read 100 articles on multithreading you will have 100 multithreading techniques most of which say the other 99 are wrong.
|
|
|
|
|
|
ODBC articles were like that. Like you I stop reading when I get one to work
|
|
|
|
|
El Corazon wrote: all 100 are wrong, I haven't written an article about it yet....
I am joking!! I am! I am!
You wrote one but your bosses nuked it when they went paranoid?
3x12=36
2x12=24
1x12=12
0x12=18
|
|
|
|
|
I will martyr myself and be the first to admit that I don't think in terms of parallel programming at all.
Perhaps its the nature of the assignments I get. Perhaps a lack of the wherewithal to see the opportunities.
I won't even use the excuse that my employer's systems (including my own) are all single-core.
Will others dare to so bare their very souls before this august forum?
(Sigh . . . But now I feel a lot better)
/xml> "The difference between genius and stupidity is that genius has its limits." - Albert Einstein
| "As far as we know, our computer has never had an undetected error." - Weisert
| "If you are searching for perfection in others, then you seek dissappointment. If you are searching for perfection in yourself, then you seek failure." - Balboos HaGadol Mar 2010
|
|
|
|
|
|
OK I will out myself too. I never worry about it. My code runs on my dual core desktop or on the single core target and I never worry my head about it. Sorry.
------------------<;,><-------------------
|
|
|
|
|
I think multi-threaded programming has gotten a bad rap, largely due to the cargo cult programmers filling the rosters out there. If they can't cut/copy/paste a solution into their app, whether it's appropriate or not, they say the technology's too difficult to use or worthless. This has led to all sorts of efforts to cover up the messy details with programming libraries, language features, or entire languages.
There is a substantial learning curve, but doing multi-threaded programming properly isn't impossible. I believe the hardest part of it is deciding which activities should be in which threads. Those decisions need to be made to balance the workload over the available resources, minimizing overhead. I don't believe any of the new solutions being offered improve on this essential requirement. If the developer makes poor choices on what he 'parallelizes', the application will still perform badly, regardless of the technique.
I'll admit my point of view is probably biased. The applications I've worked on for the last 10 years or so have all been multi-process and multi-threaded process control systems. Even the user interfaces tend to be multi-threaded, with UI stuff in one thread, communications in other threads, and worker activities in more threads as needed.
|
|
|
|
|
You can run a multi-threaded application on a computer with a single CPU, and nothing will run in parallel (of course!) because the CPU can only process one instruction at a time. If you run the same application on a multi-CPU system, some things may or may not run in parallel, but if the application wasn't designed with parallelism in mind then any speed gains resulting from the additional processor are going to be mostly incidental. Designing for parallelism means (in broad strokes) identifying those tasks in your code that can truly run concurrently, and threading in such a way as to exploit that optimization.
Mind you, I'm not criticizing - you even came close to the same point in your comment. I just wanted to make it clear that multi-threading and parallelism are not interchangeable terms.
|
|
|
|
|
Agreed. Multi-threaded programming might be viewed best as a means of implementing parallelism in an application. Part of my point was that, for a lot of developers, they think the new parallism tools are going to be a 'magic bullet', without actually understanding the concept.
|
|
|
|
|
I agree, but it seems that some people just can't grok it.
I worked with a programmer who thought there was a problem with the ACE threading library - so he decided to replace ACE threading with pthreads. He just couldn't understand how C code and C++ code interacted and ended up dragging around (void* This) pointers around everywhere. Worse, sometimes (This != this). There wasn't anything wrong with ACE threading and we ended up abandoning the branch he was working on and allowing another company to *enjoy* his work.
It seems like many others can't distinguish between threading (which is inherently procedural) and objects. The idea that multiple threads can be calling different methods of the same class, or the same object, or even the same method of the same object is something that people just have problems imagining. These same people seem to have problems with C#'s new "yield return" mechanism.
Amazingly (to me), reentrancy is something that people seem to have no problems with.
Again, I agree. I don't understand why people have these problems. It is very simple to me. Unfortunately, that makes it hard to describe for people. After describing the same thing multiple ways, you want to start sentences with "This is so freakin' simple ....".
Paul
|
|
|
|
|
Paul Reeder wrote: I worked with a programmer who thought there was a problem with the ACE threading library - so he decided to replace ACE threading with pthreads. He just couldn't understand how C code and C++ code interacted and ended up dragging around (void* This) pointers around everywhere. Worse, sometimes (This != this). There wasn't anything wrong with ACE threading and we ended up abandoning the branch he was working on and allowing another company to *enjoy* his work.
Yuck. Fortunately it's been a while since I've had to deal with one of those.
|
|
|
|
|
Paul Reeder wrote: Amazingly (to me), reentrancy is something that people seem to have no problems with.
We need them here.... I spend more time fixing non-reentrant code than I should. One of our programmers programs NOTHING reentrant...
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Gary R. Wheeler wrote: There is a substantial learning curve
Why? I heard someone once tell me that all threads take is a mutex to speed them up....
But in all seriousness, I think the biggest hurdle is the idea that it can be done and we are capable of doing so. So many programmers have been taught that threads are evil, threading is hard, parallel is 666 in some strange binary code.... We echo so much of what we are taught that it becomes habit: "there is no benefit, why try?" "I can't do it, it is too hard, so why try?"
Once you learn the techniques, and like you said, there is a learning curve, you start to restructure your thoughts into code in parallel forms and make it easier. I had one advantage and that was the last lesson I learned before I dropped out of college was "there are a dozen ways to solve a problem, or implement an algorithm." Knowing that there are many ways to accomplish the same thing, I adapted to parallel much easier than most (or maybe it is because I am "old-school" ).
As such, I use everything at my disposal from GPU massive parallel to OpenMP, to thread building blocks, to my own threads. I've used it all. Lord knows I am no rocket-scientist (I just watch them at a distance ... strange flighty bunch of creatures). Hell, I am a college drop-out and I learned to thread code, so it must not be too hard....
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
El Corazon wrote: all threads take is a mutex to speed them up....
I always wondered: what did he-who-shall-not-be-mentioned-even-by-his-initials have against critical sections? If you are synchronizing threads within a process, critical sections are much more lightweight than a mutex. IIRC, they don't even require a kernel transition most of the time, unlike mutexes.
Our applications (multiple processes, many threads per process) use critical sections almost exclusively. The one mutex I'm aware of is used for ensuring only a single instance of the process is running.
|
|
|
|
|
Gary R. Wheeler wrote: I always wondered: what did he-who-shall-not-be-mentioned-even-by-his-initials have against critical sections? If you are synchronizing threads within a process, critical sections are much more lightweight than a mutex. IIRC, they don't even require a kernel transition most of the time, unlike mutexes.
I asked that once. The answer (please put down any liquids and sit down, I will not be held responsible for spewed food or liquid onto expensive monitors, laptops, cell phones or the like... or of personal fainting).... The answer is that Critical Sections are an invention of Microsoft and are not portable. Only mutexes are Unix based and therefore perfect.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
El Corazon wrote: The answer is that Critical Sections are an invention of Microsoft and are not portable.
Oh Judas H. Priest. Wrap the freakin' thing in its own class, compile it with mutexes in Unix and with critical sections under Windows. On a bad day (migraine included) I could have such a class working in five minutes, single-handed.
|
|
|
|
|
both linux and windows supports OpenMP and OpenMP supports critical sections. OpenMP is not a Microsoft invention.
logic never works with him.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Fortunately, he is dead to us now...
|
|
|
|
|
Just one question. How many people work on your code base?
|
|
|
|
|
It varies, but we have a group of a dozen maintaining four products, with a couple branches each. Why do you ask?
|
|
|
|
|
Gary R. Wheeler wrote: Why do you ask?
Because it is *relatively* easy to get multithreading right if you own the code base, but if there are multiple people introducing changes it becomes much harder. And if somebody introduces a race condition that shows up only once in a week on specific hardware - well good luck debugging that
|
|
|
|
|
Nemanja Trifunovic wrote: if there are multiple people introducing changes it becomes much harder
We, as a team, seem to have a good combination of division of labor and cooperation. We've not had very many thread synchronization issues that have arisen because of multiple people being involved in a single code base.
|
|
|
|
|
I too have been doing this for a long time. One reason is my home machine has been at least 2 cores since I had my first dual processor pentium 1 board in 1995. I started the paying job in 1997 and some of my first projects required a multithreaded design. 13 years later I am still doing multithreaded designs but for the most part not as low level as I started. I tend to now use thread pools more often and other libraries that do most of the heavy lifting for me.
John
|
|
|
|
|
John M. Drescher wrote: I tend to now use thread pools more often and other libraries that do most of the heavy lifting for me.
I'm enjoying that feature of .NET. I've got a significantly multi-threaded application in C# I've been working on for the last 18 months, and just recently I added the first 'real' thread. The rest of it has been through the BeginInvoke /EndInvoke constructs, which use the thread pool under the covers for you.
|
|
|
|
|
I have to disagree (does that label me "cargo cult" now?)
It's ok if it's your bread and butter, and you live in an environment where multithreading is everywhere.
However, adding multithreading to a pool of techniques and skills is hard. It has so many side effects and artifacts, e.g. it affects interface design, as this determines whether external locking is necessary, and preventing deadlocks requires global knowledge of the application. That's a lot of burder for libraries with "Unknown" reuse.
|
|
|
|