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

How to represent shared mutable state?
Convert String to SocketAddr
Why is a Cell used to create unmovable objects?
“entry point could not be located” when running program on Windows
Does dereference equal to a function call?
Should I use Rust 1.0-alpha or the nightly version?
How to do a binary search on a Vec of floats?
Having a child modify its parent
How do I access the data sent over UDP?
How to idiomatically copy a slice?
Recursive types and arrays
Can I determine the zero value of generic types?
How to slice a large Vec<i32> as &[u8]?
How to parse i64 from a string? [duplicate]
Why is variable scope dependent on the definition order?
Warning on “unstable” directive

Categories

HOME
cocoapods
memory
lambda
mpdf
qc
code-formatting
hdfs
dependencies
bittorrent
impala
wine
slide
locationmanager
vimeo
smooks
mailmerge
dma
android-contacts
exec-maven-plugin
spam
adobe-illustrator
home
kaggle
stackexchange.redis
quartz.net
firemonkey-style
unordered-multimap
plyr
morris.js
unrar
oracleforms
acrobat
audit
google-play-developer-api
dotcms
windows2012
reporting
bootstrap-sass
spinner
django-smart-selects
recovery
best-buy-api
get-event-store
data-uri
vb.net-to-c#
asihttprequest
nuclio
django-static-precompiler
uiautomatorviewer
embedded-v8
android-webservice
dblink
rcharts
wildfly-9
petsc
ipywidgets
mathjs
data-management
jsf-2.3
svnserve
dojo-build
distributed-cache
verisign
nastran
screen-orientation
sqlbase
textscan
tkx
kognitio-wx2
nhibernate-criteria
zend-mail
berkeley-db-xml
object-code
nidaqmx
webmethod
miglayout
sql-function
wso2bam
lsa
vlab
illuminate-container
revmob
jquery-transit
django-filebrowser
ip-geolocation
daap
java.lang.class
dropshadow
netstream
acpi
differentiation
glassfish-esb
getopts
fork-join
kernel32
ios-4.2
multiple-users
downcasting
levels
jvm-bytecode

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App