Skip to content

Technical nits: Threads and Drop #63

@QuineDot

Description

@QuineDot

This slide says that threads are all daemon threads, but this is untrue:

  • For one, you're only talking about thread::spawn created threads, as per the very next slide
  • For two, these threads are only detached if you drop the JoinHandle
  • You also mention panicking and payloads, but you can only catch unwind payloads on the current thread; for panics of another spawned thread, you call join on the join handle to see if it panicked and to get the payload
    • I.e. you can only do this if the thread isn't detached

So you should talk about JoinHandle and detaching via Drop.

On the scoped page you should talk about the different behavior:

  • ScopedJoinHandle joins and blocks upon Drop instead of detaching
  • Any dropped ScopeJoinHandle that witnesses a thread panic will cause thread::scope to panic
  • But you can manually join and check for thread panics instead, similar to JoinHandle

Aside from the ability to borrow, this difference in handle drop behavior (and thus what may panic where) is the main difference between the two tools.

Metadata

Metadata

Assignees

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