Skip to content

Defining thread safety in Parallelism Lecture #42

Closed
@jespiron

Description

@jespiron

Edit: addressing in #43
See #42 (comment)
Ignore this body


The current conclusion is strong

Rather than choosing a restrictive "dogmatic" approach to concurrency, Rust supports many approaches, safely

To make this point clearer, I recommend defining thread unsafety:

  • Condition 1: Shared memory
  • Condition 2: An invariant of shared memory that must hold for correctness, like "count is the number of times any thread has executed this function"
  • Condition 3: Invariant does NOT hold during part of the update
  • Condition 4: Program is not thread-safe if another thread can access the shared memory while invariant is broken

We achieve thread safety by removing one of the above conditions

When we explain each approach, we can show which condition it removes:

  • Mutual exclusion removes condition 4, by restricting access to at most one thread
  • Atomics remove condition 3 by making update an airtight operation
  • Message passing eliminates shared memory and thus all conditions, since each thread processes data independently through channels

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions