views:

148

answers:

4

I been looking around at the problem of the multi-core chip stuff. would I be correct in assuming that the real problem with developing for mutlicore chips is nothing to do with the actual techniques of multi-tasking (isolated memory, task based etc), but more to do with the implementation of the threading model in the OS?

I have been investigating Co-Routines and implementing them in c#,f# and python. So far they succeed very well apart from the creating the sub system and redeveloping a new sub system for every other system part, which is tiresome to say the least.

Is there a better model out there that comes "out of the box" that would serve me better and equally performant as co-routines.

+3  A: 

Well, I don't think FP magically makes code better multi-threaded than OOP. Well written Java and C++ can still do some pretty amazing parallel performance, certainly in the range of cores we can currently get on commodity servers (8-24 core range).

Personally, I am looking at FP more as a way to get more done per line of code. I like dense code. I write code I want to go fast all the time in Java, and so far the paradigm holds... just a lot of ceremony and bloat I would rather not have to write.

P.S. I wouldn't say OOP is failing, most code being written today is still OOP, and I suspect that this will continue for at least the near future.

bwawok
I would add that it is much more popular in the research community. I haven't seen it in the wild yet in industry except is special purpose applications.
rerun
There was a lot of work done in the early eighties and nineties on capturing the real world OO stuff and modelling in software. My feeling is that functional programming has it place, but there are far too many over eager people out there pushing the new thing, but forgetting what was learned.
WeNeedAnswers
This answer implies C++ is strictly an OOP language, which it isn't.
GMan
Well C++ was designed for objects (bootstrapped to C). I remember the marketing push for objects. It was the new thing and everyone wanted a piece of the pie. I remember going to an interview for a perl job and the guy getting arsey with me for getting all evangelical over objects. He didn't get objects, I didn't get the job. :) time flys.
WeNeedAnswers
+1  A: 

Have you looked into the Microsoft Coordination and Concurrenty Runtime? It's a fairly nifty way of dealing with coroutine-like problems. I've used it to write really good, scalable servers that go multicore effortlessly. I think you'll find the CCR iterator pattern to be really interesting.

spender
thanks will take a look.
WeNeedAnswers
+1  A: 

I would say that you are starting from the wrong assumption. Is OOP failing? I disagree, based on the blizzard of OOP related traffic (often specific to threading) here.

Multithreading your code is orthogonal to any type of programming but parallel programming, which enables code obeying certain strictures automatically to run thread-safe. It's just as easy to write bad multithreaded programs using functional programming constructs as using any other choice you might make.

The problem with developing code for multicore systems is not that OOP does not extend, but that writing thread-safe code is inherently more difficult than writing single-threaded code, which is hard enough in and of itself.

Steve Townsend
I never found threading to be that difficult. Just follow the rules and your ok. I agree OO is not failing. But the push for functional programming might if we are not careful destroy a really good method for modelling systems. I find c#/Java to be a little to OO for my liking though. I never liked delegates as they never fitted the OO model. OO does not lend itself well to multi-threading, as you have to break up the class from the data and this breaks the encapsulation principal.
WeNeedAnswers
+1  A: 

the real problem with developing for mutlicore chips is nothing to do with the actual techniques of multi-tasking (isolated memory, task based etc), but more to do with the implementation of the threading model in the OS?

That's false. The OS works fine. The OS threading model works fine. Evidence: The OS works really well.

The "problem" with multi-threaded applications is the standard problem all software has:

  • Data Structures

  • Algorithms

When working in a threaded environment, you must actually design the updates and memory writes carefully to prevent race conditions that cause out-of-order writes to memory. And that's just hard. Most folks don't consider locking and mutable shared data structures carefully enough.

Read this: http://www.wilsonmar.com/1threads.htm. It's hard and some people get parts of it wrong. To me, the issue seems to be that a lot of people who are able to type code like to think they're capable of designing multi-threaded applications. Perhaps too many people are messing with multi-threaded applications when they shouldn't be.

Multi-threaded application design complexity is exacerbated by the fact that the Intel processor chip has no complete, formal, precise definition for memory write ordering.

Read this: http://moscova.inria.fr/~zappa/readings/cacm10.pdf Very important stuff on what threading is made more complex by the Intel processor family.

And, optimizing compilers make this write ordering problem yet more complex.

If you do Functional Programming with immutable data structures, optimizations of memory writes may be simplified leading to better performance.

Most of the time, most programs can be broken into concurrent processes using ordinary OS pipelines. The rest of the time, a simple message queue to pass work through a pipeline-like structure gets to a high level of concurrency with no design complexity. Why? No shared mutable data structures.

S.Lott
Threading is only one model though. In some OS's the model is better than others, for example Linux provides a better model of threading than Windows. However there is more than one way to implement a multi processor system. Threading was the winner when it came around. It provided a quick and easy solution for the common programmer. If you look into threads though, they are big nasty beasts that eat up resources like me in a all you can eat Sunday buffet.
WeNeedAnswers
"Threading was the winner when it came around"? What? Any references or quotes or links? What are you talking about?
S.Lott
S.Lott you seem very combative. Why don't you just use exclamation marks everywhere. Your not actually asking me anything, just accenting your own personality, in every post you see. take a look on google. Treat yourself.
WeNeedAnswers
I'm asking for help. If you want to call it combative, that's your option. Please answer my questions. I can't understand your comment. I'm asking for help understanding your comment. Please explain your comment by providing me some reference or quote or link that I can read to understand your comment.
S.Lott
well in a modern context there is http://software.intel.com/en-us/blogs/2007/01/04/five-alternatives-to-threading/
WeNeedAnswers
@WeNeedAnswers: What is that link? Is that "Threading was the winner when it came around"? How his that threading was the winner? I can't follow your reasoning. Please explain what you are talking about.
S.Lott
and there were always co-routines.
WeNeedAnswers
Well there is more than one way to sub divide work loads. Roll your own was replaced by the whole programming threading model. I remember to divide a task up way back, you did it through shared memory and mutexes and semaphores. It was awkward but it worked, then the whole bolt on threading stuff came in and the task was done for you. Multiple applications that is.
WeNeedAnswers
"the task was done for you"? What? How so? What was done for you? What are you talking about? I can't follow your comments at all.
S.Lott
oh please, 30 years in the industry, your just playing games. You know all about forking() and shared memory. I take it your a python guy. You know all about the problems in python. stop playing games. I take it I can look forward to another bout of the question marks after this, save your ink I won't reply. :)
WeNeedAnswers
@WeNeedAnswers. "You know all about forking() and shared memory". How does "forking() and shared memory" mean that "the task was done for you"? What was done for me? Forking? That's not threading. Nor, for that matter, is shared memory. How is this all "Threading was the winner when it came around"? Please explain your comment. I can't understand what all this *means*.
S.Lott
In most modern programming languages, lets use c# as a vehicle for this, the whole problem of threading was taken out of the hands of the developer and a framework was put in place, scaffold that would do all the hard work for you. In the case of c# you just create a delegate, give it some data to play with, and spawn off a thread. In most cases it is that simple as long as you follow the atomic data principal. The framework would then hold you hand through the whole process and there is no need to worry about it that much. Its all great.
WeNeedAnswers
The alternative to threading that these days I try to use (old technique), if the system I am developing will allow for time-slicing, is using co-routines. Here is a post, http://www.dabeaz.com/coroutines/ I expect that you have already read this. :) but will humour you.
WeNeedAnswers
Reason for co-routines. Predictive results.
WeNeedAnswers