Skip to content
Snippets Groups Projects

Demo code for the course CS-206: Parallelism and concurrency

Everybody is welcome to contribute by creating merge requests!

Installation

  1. Check that you have the "Scala (Metals)" and "Scala Syntax (official)" extensions installed in VSCode.

  2. Clone this repo: git clone git@gitlab.epfl.ch:lara/cs206-demos.git.

  3. Open it with VSCode (for example using the command code . in cs206-demos).

  4. Click on "Import SBT Build":

  5. Wait while Metals runs bloopInstal:

Usage

Standard Scala files

“Normal” Scala files (ending with .scala) must have a @main method. For example, 01-java-threads.scala, the main method is testThreads. You can run it from the command-line, first by entering the sbt shell:

sbt

and then by running:

runMain javaThreads

where javaThreads is the name of a @main function. This should output something similar to:

sbt:cs206-demos> run javaThreads
[info] compiling 1 Scala source to /Users/me/cs206-demos/target/scala-3.2.0/classes ...
[info] running javaThreads javaThreads
Little threads did not start yet!
ThreadThread-3 has counter 0
ThreadThread-2 has counter 0
ThreadThread-2 has counter 1
Parent thread and children are running!
...

You can also directly run it from VSCode using the run link:

Run link displayed in VSCode

Scala worksheets

Inside src/main/scala, you can create Scala worksheets (files ending with .worksheet.sc). These are special Scala files meant for experimentation where the result of every top-level expression is directly displayed in the IDE. See the official tutorial about Scala worksheets for more details.

You can try 01-sumList.worksheet.sc as an example. If you open it in VSCode, you should see the result of all top-level expressions automatically displayed:

Example of a worksheet opened in VSCode

Try to change the code and you should see the results automatically updating!

Format code

This project uses scalafmt to format code.

You can run the formatter using sbt scalafmt.

The code style is configured in .scalafmt.conf.