---
title: "Discussion on \"Threads in rust\" | Hashnode"
description: "Discussion on \"Threads in rust\". In our regular hacksession, the current season ;), we are focusing on threading. \nConcurrency/Multithreading is a really hard topic it has a lot of very specific nomenclature and there are different 'levels' of concurrency one might say.\nI will start..."
url: "https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Threads in rust](https://chilimatic.hashnode.dev/threads-in-rust?utm_source=hashnode&utm_medium=feed)

In our regular hacksession, the current season ;), we are focusing on threading. Concurrency/Multithreading is a really hard topic it has a lot of very specific nomenclature and there are different 'levels' of concurrency one might say. I will start...

Jun 7, 2019 · chilimatic.hashnode.dev  
Updated Jun 9, 2019  
Read the article

-   [#rust](https://hashnode.com/tag/rust)
-   [#programming](https://hashnode.com/tag/programming)

## Written by

[j](https://hashnode.com/@chilimatic)

@chilimatic · Vienna, Austria

  
[View profile](https://hashnode.com/@chilimatic)

stuff ;)

dev blabla :)

## Responses 5

Markdown supported · ⌘↵ to post

[Michael Murphy](https://hashnode.com/@mmstick)

[Jun 10, 2019](https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674/comment/5cfe6b4790c6ae176ecfbdc5)

In addition to locking data structures like Mutex and RwLock, you should also mention channels like MPSC and MPMC. You may also want to mention ShardedLock from crossbeam, as well as its Parker and WaitGroup synchronization primitives. Rayon's thread pools and scoped threads are also very important to be aware of when dealing with threads in Rust.

[j](https://hashnode.com/@chilimatic)

[Jun 10, 2019](https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674/comment/5cfe6b4790c6ae176ecfbdc5#reply-5cfe6fca90c6ae176ecfbdd7)

[Michael Murphy](https://hashnode.com/@mmstick) I will try to work through them. I wanted to go through the channels when I do the different concurrency models like actors and such. thank you :) for your feedback :)

[Joseph S Stevens](https://hashnode.com/@josephscottstevens)

[Jun 8, 2019](https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674/comment/5cfbe887f54348e967cb0659)

Very cool, Rust is something I really want to do some day. I am beyond sold! :D

[Mark](https://hashnode.com/@mverleg)

[Jun 7, 2019](https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674/comment/5cfacde358d2afbf3c17ec51)

This is very detailed, way more interesting facts than I was expecting.

I think many of the sections cover big enough topics that they could've been whole posts, so probably not an introduction level post. But personally I liked that, good to see some in-depth posts!

> A RefCell is not threadsafe

Just to clarify for those less familiar with Rust: you can't actually do anything unsafe - you just can't share it between threads at all, it won't compile.

I tend to end up with `RwLock`s when doing threading code, not sure if that's a problem... Probably not super performance, but it's easy, and I like the way Rust ensures that you lock long enough but not too long.

I only found out after a while that `RwLock` exists and while less fair, is often faster than `Mutex` (which seems to be the most mentioned online). \[By 'less fair' I mean that, in my understanding, it does not give equal chance to each thread... I think it can starves out writes?\]

[j](https://hashnode.com/@chilimatic)

[Jun 8, 2019](https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674/comment/5cfacde358d2afbf3c17ec51#reply-5cfb9c227ef4b1a112ac6993)

[Mark](https://hashnode.com/@mverleg) Actually I fell like there should be way more things in there. But my blogs are usually more of katharsis and I always feel like there are so many pieces missing that I should add.

RWLocks, if I read this correct there are different approaches to the preferences if the kernel starves the reader or the writers. Which is a very interessting point I did not know. I was going for my mental model and your point helps a lot :) thx. I will add it up there as well.

[sites.google.com/site/embeddedmonologue/home/mutu…](https://sites.google.com/site/embeddedmonologue/home/mutual-exclusion-and-synchronization/rwlock-and-reader-writer-starvation)

for more details :)

[Fahmi Akbar Wildana](https://hashnode.com/@DrSensor)

[Jun 7, 2019](https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674/comment/5cfab8a2e8d77b2225d6491d)

I wonder how hyperthreading diagram looks like 🤔

[j](https://hashnode.com/@chilimatic)

[Jun 8, 2019](https://hashnode.com/posts/threads-in-rust/5cfa96c13457f5cf463c2674/comment/5cfab8a2e8d77b2225d6491d#reply-5cfba599e70dc53630df01f3)

[Fahmi Akbar Wildana](https://hashnode.com/@DrSensor) I wrote and answer in the addendum. I am not sure if I add confusion or if it helps :)
