blog.grace.moe

Source for the blog blog.grace.moe
git clone https://git.grace.moe/blog.grace.moe
Log | Files | Refs

cs3211.smd (2270B)


      1 ---
      2 .title = "CS3211 Tutorial 10",
      3 .date = @date("2025-04-14T16:12:01+08:00"),
      4 .author = "Grace Tan",
      5 .description = "CS3211 Tutorial 10",
      6 .layout = "page.shtml",
      7 .alternatives = [{
      8     .name = "raw",
      9     .layout = "page.raw.shtml",
     10     .output = "index.raw.html",
     11 }],
     12 .draft = false,
     13 ---
     14 
     15 # CS3211 Tutorial 10
     16 
     17 (Will delete after a few weeks)
     18 
     19 (Will be ready like maybe tomorrow)
     20 
     21 ## Overall themes in CS3211
     22 
     23 - How to specify concurrency.
     24   - Use std::thread, goroutines, async tasks, scoped threads, Rayon, ...
     25 - How to deal with synchronization.
     26   - Use std::mutex, channels, ...
     27 - The rules around concurrency.
     28   - C++ memory model, borrow checking.
     29 
     30 Ultimately, all these themes show up in other languages as well!
     31 
     32 e.g. asyncio in Python https://docs.python.org/3/library/asyncio-task.html
     33 
     34 ## Overall trend
     35 
     36 - **C++**: Do synchronization manually, put everything in shared memory.
     37 - **Go**: Shared memory is bad because races, put everything in channels.
     38 - **Rust**: Channels are slow and prone to deadlocks, structure the code itself so you don't have these problems.
     39 - **Future languages**: Even Rust doesn't do structured concurrency the best, solve problems magically...
     40 
     41 ## Channels are bad
     42 
     43 https://www.jtolio.com/2016/03/go-channels-are-bad-and-you-should-feel-bad/
     44 
     45 https://news.ycombinator.com/item?id=43670373
     46 
     47 ## Exam prep
     48 
     49 - Don't rush through the MCQ portion, don't forget that's actually the majority of the marks!
     50 - Practice questions available on Canvas.
     51 
     52 ## My approach for solving the memory model questions
     53 
     54 - Try to understand the rough structure of the code.
     55   - Pay attention to infinite while loops!
     56 - If there's a chance for a data race, try to check those first.
     57 - Then solve each T/F question.
     58 
     59 ## Open ended coding questions
     60 
     61 Remember we're trying to test for your knowledge in what we taught in the module, not necessarily whether you know all the syntax perfectly. So don't stress too much about getting the correct function name etc., just write something that indicates you know the concept!
     62 
     63 Some parts you shouldn't handwave away though --- remember the goal is to show you understood the module. So for example, when answering a Go question, the flow of the data and how the channels are set up is very important to make clear!