27

Don't overcomplicate things. Your first instinct, that the computer only has one hand, was the correct one. This is a regular problem that new teachers have, and it sometimes takes a few years of frustration to burn out the idea that everything you say must be formally true. If we say something that is untrue, the reasoning goes, the students will remember ...


22

Re-evaluate what you think is "right", because you aren't but isn't right in computer science This is simply incorrect. Your student can create two variables called LeftHand and RightHand. Copy value "red" from position 1 to LeftHand, copy value "green" from position 4 to RightHand, copy values back to positions 4 and 1 ...


16

Your problem is that you tried to let your student "program" without establishing a language. Thus they were free to write their own "language" in which you can do two things at once because you have two hands. If you'd asked them to rotate 3 objects, they would have picked up the third pencil in their mouth or so. You could have asked ...


10

If we don't introduce parallel/concurrent thinking early, our students can develop a sequential mindset that makes it hard for them to make the shift later. The rest of this is in the context of a college/university CS curriculum... Multithreading can be discussed in CS1 if the students build GUIs, since the GUI needs its own thread to maintain ...


9

One reason infinite loops are used could be so the problem can't be solved by letting one thread complete the code before the other thread starts it. With infinite loops, no thread ever completes the code. Of course, using a bounded buffer has the same effect.


5

This question reminds me of when a student failed to understand why a third variable was needed to exchange the value of two variables (i.e. to swap A and B, C=A, A=B, B=C). I managed to illustrate this to them by placing an item (mobile phone) in each of their hands, and asking them to swap the items between the hands. On attempting to do this, they ...


5

We're introducing some aspects of parallel processing quite early on in Scratch. Each sprite has its own script which appears to execute in parallel with those of the others. Scratch has a broadcast and receive message protocol, and support for shared as well as private variables and lists. Children might encounter this in a maze game, perhaps programming ...


5

"processes that run and enter critical sections ... where the code is not in an infinite loop" Processes are generally components of a reactive system (like an OS) that are designed to be non-terminating (hopefully, otherwise we call it a "crash"!). So even if the code of the process doesn't contain an infinite loop, the process will be invoked an ...


4

Concurrent programming is easy, synchronisation is hard. Have a look at this video for an alternative to synchronisation: https://www.youtube.com/watch?v=2yXtZ8x7TXw When you have to synchronize Use easy (High level) synchronization. see: Scoop from Eiffel. Transactions Pipelines / message passing coroutines (for when you don't need parallelisation) See ...


4

They took both their hands, picked up the second and fourth pencils (each in one hand), and swapped them! That works in reality... but isn't right in computer science. It depends on your paradigm. You are teaching the swap algorithm you know, but haven't explained to the students (or at least in the question) what things are. Here is a perfectly valid ...


3

Since the OP asked about functional programming, so I would highly recommend you to read "Learning Concurrent Programming in Scala" by Aleksandar Prokopec, (2014). All the examples for this book are available on GitHub to give you some idea of the book before you purchase it. C# I would recommend you to read "Professional Parallel Programming with C#" - ...


3

I do the swap example pretending to have two largish (2-hands-to-lift) boxes side-by-side on a desk (with only enough room for two boxes). After we lift the first we have to look for a place to put it, which feels like creating the temp variable. But I don't think swap is an especially good example with lists. It's easier to explain swapping just any two ...


3

In thinking about this, and especially the answer of Graham, I think that what we really do in the standard three step process is a two handed swap without thinking of it. So, it is a failure of the metaphor, actually. So, here is a reframing of the standard process: Pick up one stick with the left hand (i.e. temp is associated with the left hand). THEN, ...


3

Analogies & metaphors are imperfect, so let's share the expectation that they are just illustrative. Rules of what is possible (and not) are very important, and we can compare the rules of pencils moved with hands and what computers can do — but we need to define both, in part so the rules for the metaphor can be compared with the those of a computer. ...


2

Graham pointed out that the assumtions of the question are wrong. And Peter Cordes elaborated a bit in the comments. Considering a target VLIW (Very Long Instruction Word) architecture can help sharpen this argument further. The basic idea of VLIW is that a Very Long Instruction "horizontally" packs a number of instructions per single VL-...


2

Ben's answer is great, but allow me to suggest that you don't need to "respond" to the two-handed approach at all: just say when you're explaining the problem in the first place that they can only use one hand and they can only hold one item at a time. Students are less likely to need a justification this way, because you haven't changed the rules ...


2

The Well Grounded Java Developer has an excellent section on concurrency. The author claims that very few developers correctly implement concurrency. As ctrl-alt-delor put it: concurrency is easy; synchronization is hard. In fact, avoiding errors from race conditions and unexpected asynchronous behavior is so difficult that the author recommends developers ...


2

I have no recommendations for the theory part but since you are asking for implementation advice as well, here we go. If you are looking to use C sharp (you haven't specified a specific language of choice) then, as a dot net guy myself, I would recommend you start your self learning on concurrent programming with .NET implementation of same at Threads and ...


2

I do not see much value in teaching more than an appreciation of threads and locking, until you have covered less primitive techniques for parallelism. These techniques allow parallelism that scales beyond what threads and lock does, is easier to learn, and less prone to bugs. Functional programming: Pure functional programmes do not have the concept of ...


2

In UK at A-level We cover the following. Multi-core, semaphores, queues, process pipeline, SISD, MISD, SIMD, MIMD. We don't specifically cover how to write programs using these. A student could also get a good grade and know little about there.


2

Given the type of software development that occurs these days, such as on mobile phones and with "big data" technologies, I think concurrency, threading, etc. should be introduced very early. Basically as soon as you start talking about what a program is, how it's invoked or executed, and what happens when it completes, I would discuss all that in the ...


Only top voted, non community-wiki answers of a minimum length are eligible