Chapter 8. Multithreading and concurrency: running many programs at once

 

This chapter covers

  • Using spork to turn functions into concurrent shreds
  • Using Machine.add() and other virtual machine functions
  • Composing music using separate, concurrent shreds
  • Using concurrency to control multiple aspects of objects
  • Organizing your concurrent ChucK files and projects

In your ChucK journey so far, you’ve learned how to write single ChucK programs that create sound and music. But many of you may wonder how you can get ChucK to run multiple files and processes concurrently. You might have clicked the Add Shred button a few times and noted that multiple programs can happily run and make sound at the same time. Or, you might be curious what the advantages of running multiple programs at once might be. Running multiple shreds at once, or concurrency, is what this chapter is all about.

As a real-life example of concurrency, imagine you’ve been really busy and haven’t had time to do your laundry. Imagine that you have many loads of laundry to do—whites, darks, sheets, and towels—and you start by running your whites in the washing machine and then transfer them to the dryer. After they dry, you continue by washing and drying your darks, and then your sheets, and finally your towels. This would take a long time!

8.1. Programming with concurrency

8.2. Shreds and sporking

8.3. A parallel, multithreaded, concurrent drum machine

8.4. Using concurrency to control aspects of common objects

8.5. Machine commands: adding ChucK files as new shreds

8.6. Example: building a multithreaded jazz band

8.7. Summary