Answers.Body: <p>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 context of a concurrent environment.  You don't necessarily need to get into all of the details initially but I would try to avoid teaching new students that all programs are sequential and uninterruptible. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T22:23:59.410Z
Answers.LastActivityDate: 2017-06-24T22:23:59.410Z
Answers.UserDisplayName: Uncle Long Hair
Answers.Body: <h2>In UK at A-level</h2>
  
  <p>We cover the following.</p>
  
  <p>Multi-core, semaphores, queues, process pipeline, SISD, MISD, SIMD, MIMD.</p>
  
  <p>We don't specifically cover how to write programs using these. A student could also get a good grade and know little about there.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-30T17:04:14.990Z
Answers.LastActivityDate: 2017-07-30T17:04:14.990Z
Answers.UserDisplayName: ctrl-alt-delor
Answers.Body: <p>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.</p>
  
  <p>These techniques allow parallelism that scales beyond what threads and lock does, is easier to learn, and less prone to bugs.</p>
  
  <ul>
  <li>Functional programming: Pure functional programmes do not have the concept of time, so can be re-arranged, and split across processors.</li>
  <li>Pipeline programming: Writing programs to use a pipeline, to do some work and pass it to another process (sometimes used with process farms). </li>
  <li>Transactional programming: Instead of asking a node for its state, then changing it, and passing back a new state (with lock). Pass a transaction (a bit of code) to the node, the node can then execute the transaction for you with out locks.</li>
  <li>Immutable state: (see also functional programming.) If you don't change data then you don't have to lock it. Like a bank statement: it has a list of transactions, you can calculate the balance from these. Updating the balance requires a lock. Therefore don't update the balance. You may say the balance at the end of July is £5.43, but this is not <strong>the</strong> balance, it is the balance at a time.</li>
  <li>SCOOP: Uses contracts to create thread safe code.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-30T17:22:29.213Z
Answers.LastActivityDate: 2017-07-30T17:22:29.213Z
Answers.UserDisplayName: ctrl-alt-delor
Answers.Body: <p>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...</p>
  
  <p>Multithreading can be discussed in CS1 if the students build GUIs, since the GUI needs its own thread to maintain responsiveness while the main thread is handling time-consuming GUI events.  But most GUI libraries do this multithreading for you, so the students don't have to do it themselves -- you can talk about what's going on under the surface, but the students don't gain any hands-on experience and it's unclear to me how much they take away if they don't have to do it themselves. But there are schools that take this approach.</p>
  
  <p>We introduce students to multithreading in CS2 (<em>Data Structures</em>), using Just-In-Time pedagogy.  The basic idea is to give the students a problem that requires them to store a <em>lot</em> of data in a data structure (e.g., an organism's genome in a C++ vector or a Java ArrayList, or a really big image to be processed) -- enough data that processing the data sequentially takes 5-15 seconds.  This is an eternity for todays students and they get impatient waiting so long for their program to solve the problem.  We leverage that impatience and use it as motivation for introducing multithreading and parallel execution as a means of speeding up the program. We think the CS2 (<em>Data Structures</em>) course is the first time there is a natural motivation for introducing multithreading, since that's the first time you can store enough data to really motivate it.</p>
  
  <p>Our CS3 course is an <em>Algorithms</em> course, so we continue the exposure there by introducing parallel versions of searching and sorting algorithms, graph algorithms, etc. </p>
  
  <p>Our fourth course is <em>Programming Languages</em>, where we spend 1-2 weeks on languages that provide features for parallel / concurrent execution.  For example, we contrast languages that expect threads to communicate via shared memory (and the different mechanisms to synchronize those accesses: semaphores, locks, condition variables, monitors) with languages that have threads communicate via message passing (e.g., Erlang, Scala).</p>
  
  <p>Our sixth course is <em>OS &amp; Networking</em>, where spend several weeks exploring the implementation of the features needed to do all of this: threads, processes, semaphores, locks, condition variables, message-passing systems, etc.</p>
  
  <p>The upshot is that parallel and concurrency topics are "sprinkled" throughout our curriculum, rather than being confined to a single course.  (We also offer a junior-senior elective course that focuses solely on parallel computing, so that students who want more can dig deeper into the subject.) That's one way to do it.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T21:52:51.730Z
Answers.Text: This is an excellent answer. Thorough, and we'll thought-out. Welcome to [cseducators.se]. I hope we get to hear more from you!
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-25T12:34:48.277Z
Answers.Text: I like having concurrency spread over the whole curriculum as a concept, I think that makes a lot of sense and that's how we do it in high school level CS, too. I love the "leverage impatience" approach, too. But I'm not so sure about the first paragraph as a general statement ("introduce concurrency early to not lock students into a sequential mindset"), because getting concurrency right is hard - much harder than sequential thinking - and I don't think getting used to sequential solutions first actually makes later introduction of concurrency more difficult.
Answers.UserDisplayName: Pascal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T21:04:25.320Z
Answers.LastActivityDate: 2017-06-24T21:04:25.320Z
Answers.UserDisplayName: Joel Adams
Answers.Body: <p>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. </p>
  
  <p>Children might encounter this in a maze game, perhaps programming a number of similar ghosts to chase the player's avatar. It's also useful for agent-based modelling, e.g. the spread of an epidemic through a population. </p>
  
  <p>Of course, it's not true multi-threading, as all of Scratch runs inside Flash, inside the browser, on just the one core, but I doubt those using Scratch will be aware of, or care about, the distinction.</p>
  
  <p>This does, though, lead to potential difficulties in 'graduating' from Scratch to a text-based language such as Python - young Scratchers who've been used to programming in parallel in Scratch can find it hard to adjust to doing just one thing at a time in introductory Python programming.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-13T05:12:15.477Z
Answers.Text: Switching from Scratch to Python will probably feel like switching from space travel to inventing the wheel.
Answers.UserDisplayName: Gypsy Spellweaver
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-25T11:33:08.080Z
Answers.LastActivityDate: 2017-05-25T11:33:08.080Z
Answers.UserDisplayName: Miles
Body: <p>Given the current trends with Moore's law and computer systems design, where even the cheapest cell phones and Raspberry Pi's, etc., are multi-threaded multi-processors, and any gains in performance (per Watt, per dollar, etc.) seem to be heading towards even more concurrent hardware:</p>
  
  <p>How early should the concepts of parallel computation be introduced in computer science education (as the almost required default form of actual programming practice)?</p>
  
  <p>What are the minimum prerequisite concepts before the requirement of concurrent thinking be introduced?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-31T11:00:13.620Z
Comments.Text: I didn't do a CS degree, but I did learn mutli threading at my first year of studying after high school, however it was because I had finished the past exercices already (i was quite above the level of our classe because I already practiced programmation before with PHP/web). I learned fork() and process intercommunication (pipe, socket, semaphore,file, ...) right before.
Comments.UserDisplayName: Walfrat
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-08T02:37:23.487Z
Comments.Text: 30 years ago, the typical student PC did not have an OS that supported multi-threading or multiple processors.  Whereas today, a typical student's mobile phone might expose quad or octo CPUs running 100's of processes.
Comments.UserDisplayName: hotpaw2
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-24T17:29:58.800Z
Comments.Text: Basic knowledge of data structures is necessary, as a few synchronization mechanisms use queues. You could potentially include it in a data structures course IMO. pthreads could be confusing at this level, though. C++11 threads would be a better choice.
Comments.UserDisplayName: xuq01
Tags: <concurrency>
Title: When should concurrency and parallel multi-processing concepts be introduced?
ThreadText: # When should concurrency and parallel multi-processing concepts be introduced?
  
  (Asked by: username_0 on 2017-05-23)
  
  Given the current trends with Moore's law and computer systems design, where even the cheapest cell phones and Raspberry Pi's, etc., are multi-threaded multi-processors, and any gains in performance (per Watt, per dollar, etc.) seem to be heading towards even more concurrent hardware:
  
  How early should the concepts of parallel computation be introduced in computer science education (as the almost required default form of actual programming practice)?
  
  What are the minimum prerequisite concepts before the requirement of concurrent thinking be introduced?
  
  **Tags:** concurrency
  
  > **Comments:**
  > **username_2**: Basic knowledge of data structures is necessary, as a few synchronization mechanisms use queues. You could potentially include it in a data structures course IMO. pthreads could be confusing at this level, though. C++11 threads would be a better choice.  
  > **username_1**: I didn't do a CS degree, but I did learn mutli threading at my first year of studying after high school, however it was because I had finished the past exercices already (i was quite above the level of our classe because I already practiced programmation before with PHP/web). I learned fork() and process intercommunication (pipe, socket, semaphore,file, ...) right before.  
  > **username_0**: 30 years ago, the typical student PC did not have an OS that supported multi-threading or multiple processors.  Whereas today, a typical student's mobile phone might expose quad or octo CPUs running 100's of processes.  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_5 on 2017-06-24. Score: 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 responsiveness while the main thread is handling time-consuming GUI events. But most GUI libraries do this multithreading for you, so the students don't have to do it themselves -- you can talk about what's going on under the surface, but the students don't gain any hands-on experience and it's unclear to me how much they take away if they don't have to do it themselves. But there are schools that take this approach.
  
  We introduce students to multithreading in CS2 (*Data Structures*), using Just-In-Time pedagogy. The basic idea is to give the students a problem that requires them to store a *lot* of data in a data structure (e.g., an organism's genome in a C++ vector or a Java ArrayList, or a really big image to be processed) -- enough data that processing the data sequentially takes 5-15 seconds. This is an eternity for todays students and they get impatient waiting so long for their program to solve the problem. We leverage that impatience and use it as motivation for introducing multithreading and parallel execution as a means of speeding up the program. We think the CS2 (*Data Structures*) course is the first time there is a natural motivation for introducing multithreading, since that's the first time you can store enough data to really motivate it.
  
  Our CS3 course is an *Algorithms* course, so we continue the exposure there by introducing parallel versions of searching and sorting algorithms, graph algorithms, etc.
  
  Our fourth course is *Programming Languages*, where we spend 1-2 weeks on languages that provide features for parallel / concurrent execution. For example, we contrast languages that expect threads to communicate via shared memory (and the different mechanisms to synchronize those accesses: semaphores, locks, condition variables, monitors) with languages that have threads communicate via message passing (e.g., Erlang, Scala).
  
  Our sixth course is *OS & Networking*, where spend several weeks exploring the implementation of the features needed to do all of this: threads, processes, semaphores, locks, condition variables, message-passing systems, etc.
  
  The upshot is that parallel and concurrency topics are "sprinkled" throughout our curriculum, rather than being confined to a single course. (We also offer a junior-senior elective course that focuses solely on parallel computing, so that students who want more can dig deeper into the subject.) That's one way to do it.
  
  > **Comments:**
  > **username_6**: This is an excellent answer. Thorough, and we'll thought-out. Welcome to [cseducators.se]. I hope we get to hear more from you!  
  > **username_7**: I like having concurrency spread over the whole curriculum as a concept, I think that makes a lot of sense and that's how we do it in high school level CS, too. I love the "leverage impatience" approach, too. But I'm not so sure about the first paragraph as a general statement ("introduce concurrency early to not lock students into a sequential mindset"), because getting concurrency right is hard - much harder than sequential thinking - and I don't think getting used to sequential solutions first actually makes later introduction of concurrency more difficult.  
  
  ---
  
  ### Answer by username_8 on 2017-05-25. Score: 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 a number of similar ghosts to chase the player's avatar. It's also useful for agent-based modelling, e.g. the spread of an epidemic through a population.
  
  Of course, it's not true multi-threading, as all of Scratch runs inside Flash, inside the browser, on just the one core, but I doubt those using Scratch will be aware of, or care about, the distinction.
  
  This does, though, lead to potential difficulties in 'graduating' from Scratch to a text-based language such as Python - young Scratchers who've been used to programming in parallel in Scratch can find it hard to adjust to doing just one thing at a time in introductory Python programming.
  
  > **Comments:**
  > **username_9**: Switching from Scratch to Python will probably feel like switching from space travel to inventing the wheel.  
  
  ---
  
  ### Answer by username_3 on 2017-06-24. Score: 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 context of a concurrent environment. You don't necessarily need to get into all of the details initially but I would try to avoid teaching new students that all programs are sequential and uninterruptible.
  
  
  ---
  
  ### Answer by username_4 on 2017-07-30. Score: 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.
  
  
  ---
  
  ### Answer by username_4 on 2017-07-30. Score: 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 time, so can be re-arranged, and split across processors.
  * Pipeline programming: Writing programs to use a pipeline, to do some work and pass it to another process (sometimes used with process farms).
  * Transactional programming: Instead of asking a node for its state, then changing it, and passing back a new state (with lock). Pass a transaction (a bit of code) to the node, the node can then execute the transaction for you with out locks.
  * Immutable state: (see also functional programming.) If you don't change data then you don't have to lock it. Like a bank statement: it has a list of transactions, you can calculate the balance from these. Updating the balance requires a lock. Therefore don't update the balance. You may say the balance at the end of July is £5.43, but this is not **the** balance, it is the balance at a time.
  * SCOOP: Uses contracts to create thread safe code.
  
  
  ---
  
  