Send and Sync

๋Ÿฌ์ŠคํŠธ๋Š” ์•„๋ž˜ ๋‘๊ฐ€์ง€ ํŠธ๋ ˆ์ดํŠธ๋ฅผ ์ด์šฉํ•˜์—ฌ ์Šค๋ ˆ๋“œ ๊ฐ„ ๊ณต์œ  ์ ‘๊ทผ์„ ๊ธˆ์ง€๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • Send: T๊ฐ€ ์Šค๋ ˆ๋“œ ๊ฐ„ ์ด๋™์ด ์•ˆ์ „ํ•˜๋‹ค๋ฉด, T์˜ ํƒ€์ž…์€ Send์ž…๋‹ˆ๋‹ค.
  • Sync: &T๊ฐ€ ์Šค๋ ˆ๋“œ ๊ฐ„ ์ด๋™์ด ์•ˆ์ „ํ•˜๋‹ค๋ฉด, &T์˜ ํƒ€์ž…์€ Sync์ž…๋‹ˆ๋‹ค.

How does Rust know to forbid shared access across thread? The answer is in two traits:

  • Send: a type T is Send if it is safe to move a T across a thread boundary.
  • Sync: a type T is Sync if it is safe to move a &T across a thread boundary.