rust


What is the role of Send and Sync in libcore?


Sync and Send play a big role in the thread API from the standard library. However, they are also included in libcore. Within the latter, there are a few types that implement them, but I can't find any "consumers", that is, some API that would use those traits as bounds.
Do they have some special behavior/meaning that the compiler knows about? Notice that they are lang items, so they are in some way special. Sync seems to be related to statics, but the link does not go into much detail.
TL;DR: if Send and Sync are about thread-safety, what role do they fulfill in libcore where there is no notion of multi-threading? What semantics does the compiler assign to them as lang items?
if Send and Sync are about thread-safety, what role do they fulfill in libcore where there is no notion of multi-threading?
libcore is about setting the core concepts of the language; Send and Sync are core to the language: the compiler knows and reasons about them1.
The fact that libcore does not use multi-threading itself is orthogonal and has no incidence on this choice.
As an aside, do consider that just because libcore does not have multi-threading does not mean that one cannot built an alternative standard library on top of libcore that does have multi-threading. That is, after all, the purpose of separating core from std.
1 As mentioned by #kennytm in comments, Rust has a user-accessible mechanism to allow automatically propagating marker traits based on whether said traits are implemented by all a structure fields, or not. This is slightly insufficient for Send and Sync, though, as it does not support &(Trait + Send), and therefore the compiler requires special knowledge about those two, which is why they are lang items.
The compiler will crash if you declare a static variable and no Sync trait exists.
After all, just because we don't have libstd's implementation of threads in play doesn't mean there's no concurrent access going on (if you're bare metal, you probably have interrupt handlers to worry about). So, for static variables to be safe, the compiler needs to know if the static variable can be safely accessed concurrently or not.

Related Links

Problems with mutability in a closure
Lifetime differences between references to zero sized types
Assignment from Rust match statement
Easily convert third party Errors to String
Why does Cargo create multiple directories for the same registry?
Struct with a generic trait which is also a generic trait
Rustup vs Cargo binaries
How to redirect child process output to stderr?
Why does Rust not permit type inference for local constants?
How do I find the function pointers for tests from the LLVM IR code of a Rust program?
How to check in Rust if architecture is 32 or 64 bit?
How can I succinctly combine many `Result`s of different types?
Why is the produced assembly not equivalent between returning by reference and copy when inlined?
include module from the same directory level [duplicate]
Is there a way to prevent emitted LLVM IR from removing unused functions?
Does Cargo support custom profiles?

Categories

HOME
elasticsearch
orientdb
apache-nifi
mc
yahoo-weather-api
android-fragments
compilation
braintree
histogram
gallery
qooxdoo
google-sheets-query
vue-resource
visualforce
clone
anchor
mutation-testing
azure-graph-api
grocery-crud
createjs
corona
yii2-basic-app
generator
ava
prompt
ipa
code-climate
sfml
openbr
toad
series
buildforge
code-rally
twilio-php
mv
xll
linq.js
oauth2
icepdf
optionaldataexception
spooler
bit-shift
sonarqube5.2
roracle
icecast
dex
alertify
gapi
yargs
ogg
haraka
yui3
zynq
callouts
sharepoint-apps
webgrind
miniconda
smart-tv
lowercase
vdm-sl
green-threads
ipod
dbmigrate
clarion
whitespace-language
shoes
sablecc
mxe
incron
tabris
full-text-indexing
siena
sqlbindparameter
accountmanager
ember-table
jsplitpane
system-requirements
multiple-dispatch
taskkill
motodev-studio
snackjs
data-dump
representation
canonicalization
android-2.1-eclair
activestate
tabbarcontroller
community-server

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App