Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > fdedb3cf2140df9b6d419a2338ab1caa > files > 1699

rust-doc-1.25.0-1.mga6.x86_64.rpm

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <meta name="description" content="API documentation for the Rust `Sync` trait in crate `core`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, Sync">

    <title>core::marker::Sync - Rust</title>

    <link rel="stylesheet" type="text/css" href="../../normalize.css">
    <link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle">
    
    <link rel="stylesheet" type="text/css" href="../../dark.css">
    <link rel="stylesheet" type="text/css" href="../../main.css" id="themeStyle">
    <script src="../../storage.js"></script>
    

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc trait">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <nav class="sidebar">
        <div class="sidebar-menu">&#9776;</div>
        <a href='../../core/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
        <p class='location'>Trait Sync</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>core</a>::<wbr><a href='index.html'>marker</a></p><script>window.sidebarCurrent = {name: 'Sync', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
    </nav>

    <div class="theme-picker">
        <button id="theme-picker" aria-label="Pick another theme!">
            <img src="../../brush.svg" width="18" alt="Pick another theme!">
        </button>
        <div id="theme-choices"></div>
    </div>
    <script src="../../theme.js"></script>
    <nav class="sub">
        <form class="search-form js-only">
            <div class="search-container">
                <input class="search-input" name="search"
                       autocomplete="off"
                       placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
                       type="search">
            </div>
        </form>
    </nav>

    <section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Trait <a href='../index.html'>core</a>::<wbr><a href='index.html'>marker</a>::<wbr><a class="trait" href=''>Sync</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'>
                   <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
                       [<span class='inner'>&#x2212;</span>]
                   </a>
               </span><a class='srclink' href='../../src/core/marker.rs.html#343-345' title='goto source code'>[src]</a></span></h1>
<pre class='rust trait'><div class="docblock attributes">#[lang = "sync"]
</div>pub unsafe auto trait Sync { }</pre><div class='docblock'><p>Types for which it is safe to share references between threads.</p>
<p>This trait is automatically implemented when the compiler determines
it's appropriate.</p>
<p>The precise definition is: a type <code>T</code> is <code>Sync</code> if <code>&amp;T</code> is
<a href="trait.Send.html"><code>Send</code></a>. In other words, if there is no possibility of
<a href="../../reference/behavior-considered-undefined.html">undefined behavior</a> (including data races) when passing
<code>&amp;T</code> references between threads.</p>
<p>As one would expect, primitive types like <a href="../../std/primitive.u8.html"><code>u8</code></a> and <a href="../../std/primitive.f64.html"><code>f64</code></a>
are all <code>Sync</code>, and so are simple aggregate types containing them,
like tuples, structs and enums. More examples of basic <code>Sync</code>
types include &quot;immutable&quot; types like <code>&amp;T</code>, and those with simple
inherited mutability, such as <a href="../../std/boxed/struct.Box.html"><code>Box&lt;T&gt;</code></a>, <a href="../../std/vec/struct.Vec.html"><code>Vec&lt;T&gt;</code></a> and
most other collection types. (Generic parameters need to be <code>Sync</code>
for their container to be <code>Sync</code>.)</p>
<p>A somewhat surprising consequence of the definition is that <code>&amp;mut T</code>
is <code>Sync</code> (if <code>T</code> is <code>Sync</code>) even though it seems like that might
provide unsynchronized mutation. The trick is that a mutable
reference behind a shared reference (that is, <code>&amp; &amp;mut T</code>)
becomes read-only, as if it were a <code>&amp; &amp;T</code>. Hence there is no risk
of a data race.</p>
<p>Types that are not <code>Sync</code> are those that have &quot;interior
mutability&quot; in a non-thread-safe form, such as <a href="../cell/struct.Cell.html"><code>cell::Cell</code></a>
and <a href="../cell/struct.RefCell.html"><code>cell::RefCell</code></a>. These types allow for mutation of
their contents even through an immutable, shared reference. For
example the <code>set</code> method on <a href="../cell/struct.Cell.html"><code>Cell&lt;T&gt;</code></a> takes <code>&amp;self</code>, so it requires
only a shared reference <a href="../cell/struct.Cell.html"><code>&amp;Cell&lt;T&gt;</code></a>. The method performs no
synchronization, thus <a href="../cell/struct.Cell.html"><code>Cell</code></a> cannot be <code>Sync</code>.</p>
<p>Another example of a non-<code>Sync</code> type is the reference-counting
pointer <a href="../../std/rc/struct.Rc.html"><code>rc::Rc</code></a>. Given any reference <a href="../../std/rc/struct.Rc.html"><code>&amp;Rc&lt;T&gt;</code></a>, you can clone
a new <a href="../../std/rc/struct.Rc.html"><code>Rc&lt;T&gt;</code></a>, modifying the reference counts in a non-atomic way.</p>
<p>For cases when one does need thread-safe interior mutability,
Rust provides <a href="../sync/atomic/index.html">atomic data types</a>, as well as explicit locking via
<a href="../../std/sync/struct.Mutex.html"><code>sync::Mutex</code></a> and <a href="../../std/sync/struct.RwLock.html"><code>sync::RwLock</code></a>. These types
ensure that any mutation cannot cause data races, hence the types
are <code>Sync</code>. Likewise, <a href="../../std/sync/struct.Arc.html"><code>sync::Arc</code></a> provides a thread-safe
analogue of <a href="../../std/rc/struct.Rc.html"><code>Rc</code></a>.</p>
<p>Any types with interior mutability must also use the
<a href="../cell/struct.UnsafeCell.html"><code>cell::UnsafeCell</code></a> wrapper around the value(s) which
can be mutated through a shared reference. Failing to doing this is
<a href="../../reference/behavior-considered-undefined.html">undefined behavior</a>. For example, <a href="../../std/mem/fn.transmute.html"><code>transmute</code></a>-ing
from <code>&amp;T</code> to <code>&amp;mut T</code> is invalid.</p>
<p>See <a href="../../nomicon/send-and-sync.html">the Nomicon</a> for more
details about <code>Sync</code>.</p>
</div>
        <h2 id='implementors' class='small-section-header'>
          Implementors<a href='#implementors' class='anchor'></a>
        </h2>
        <ul class='item-list' id='implementors-list'>
    <li><div class='out-of-band'><a class='srclink' href='../../src/core/ptr.rs.html#2365' title='goto source code'>[src]</a></div><code>impl&lt;T:&nbsp;<a class="trait" href="../../core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + ?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; Sync for <a class="struct" href="../../core/ptr/struct.Unique.html" title="struct core::ptr::Unique">Unique</a>&lt;T&gt;</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/ptr.rs.html#2498' title='goto source code'>[src]</a></div><code>impl&lt;T:&nbsp;?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; !Sync for <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/marker.rs.html#348' title='goto source code'>[src]</a></div><code>impl&lt;T:&nbsp;?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; !Sync for *const T</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/marker.rs.html#350' title='goto source code'>[src]</a></div><code>impl&lt;T:&nbsp;?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; !Sync for *mut T</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#142' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicBool.html" title="struct core::sync::atomic::AtomicBool">AtomicBool</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#167' title='goto source code'>[src]</a></div><code>impl&lt;T&gt; Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicPtr.html" title="struct core::sync::atomic::AtomicPtr">AtomicPtr</a>&lt;T&gt;</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicI8.html" title="struct core::sync::atomic::AtomicI8">AtomicI8</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicU8.html" title="struct core::sync::atomic::AtomicU8">AtomicU8</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicI16.html" title="struct core::sync::atomic::AtomicI16">AtomicI16</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicU16.html" title="struct core::sync::atomic::AtomicU16">AtomicU16</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicI32.html" title="struct core::sync::atomic::AtomicI32">AtomicI32</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicU32.html" title="struct core::sync::atomic::AtomicU32">AtomicU32</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicI64.html" title="struct core::sync::atomic::AtomicI64">AtomicI64</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicU64.html" title="struct core::sync::atomic::AtomicU64">AtomicU64</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicIsize.html" title="struct core::sync::atomic::AtomicIsize">AtomicIsize</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/sync/atomic.rs.html#1000' title='goto source code'>[src]</a></div><code>impl Sync for <a class="struct" href="../../core/sync/atomic/struct.AtomicUsize.html" title="struct core::sync::atomic::AtomicUsize">AtomicUsize</a></code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/cell.rs.html#248' title='goto source code'>[src]</a></div><code>impl&lt;T&gt; !Sync for <a class="struct" href="../../core/cell/struct.Cell.html" title="struct core::cell::Cell">Cell</a>&lt;T&gt;</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/cell.rs.html#862' title='goto source code'>[src]</a></div><code>impl&lt;T:&nbsp;?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; !Sync for <a class="struct" href="../../core/cell/struct.RefCell.html" title="struct core::cell::RefCell">RefCell</a>&lt;T&gt;</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/cell.rs.html#1200' title='goto source code'>[src]</a></div><code>impl&lt;T:&nbsp;?<a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; !Sync for <a class="struct" href="../../core/cell/struct.UnsafeCell.html" title="struct core::cell::UnsafeCell">UnsafeCell</a>&lt;T&gt;</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/slice/mod.rs.html#1406' title='goto source code'>[src]</a></div><code>impl&lt;'a, T:&nbsp;<a class="trait" href="../../core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>&gt; Sync for <a class="struct" href="../../core/slice/struct.Iter.html" title="struct core::slice::Iter">Iter</a>&lt;'a, T&gt;</code></li>
<li><div class='out-of-band'><a class='srclink' href='../../src/core/slice/mod.rs.html#1523' title='goto source code'>[src]</a></div><code>impl&lt;'a, T:&nbsp;<a class="trait" href="../../core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>&gt; Sync for <a class="struct" href="../../core/slice/struct.IterMut.html" title="struct core::slice::IterMut">IterMut</a>&lt;'a, T&gt;</code></li>
</ul><script type="text/javascript" async
                         src="../../implementors/core/marker/trait.Sync.js">
                 </script></section>
    <section id='search' class="content hidden"></section>

    <section class="footer"></section>

    <aside id="help" class="hidden">
        <div>
            <h1 class="hidden">Help</h1>

            <div class="shortcuts">
                <h2>Keyboard Shortcuts</h2>

                <dl>
                    <dt><kbd>?</kbd></dt>
                    <dd>Show this help dialog</dd>
                    <dt><kbd>S</kbd></dt>
                    <dd>Focus the search field</dd>
                    <dt><kbd>↑</kbd></dt>
                    <dd>Move up in search results</dd>
                    <dt><kbd>↓</kbd></dt>
                    <dd>Move down in search results</dd>
                    <dt><kbd>↹</kbd></dt>
                    <dd>Switch tab</dd>
                    <dt><kbd>&#9166;</kbd></dt>
                    <dd>Go to active search result</dd>
                    <dt><kbd>+</kbd></dt>
                    <dd>Expand all sections</dd>
                    <dt><kbd>-</kbd></dt>
                    <dd>Collapse all sections</dd>
                </dl>
            </div>

            <div class="infos">
                <h2>Search Tricks</h2>

                <p>
                    Prefix searches with a type followed by a colon (e.g.
                    <code>fn:</code>) to restrict the search to a given type.
                </p>

                <p>
                    Accepted types are: <code>fn</code>, <code>mod</code>,
                    <code>struct</code>, <code>enum</code>,
                    <code>trait</code>, <code>type</code>, <code>macro</code>,
                    and <code>const</code>.
                </p>

                <p>
                    Search functions by type signature (e.g.
                    <code>vec -> usize</code> or <code>* -> vec</code>)
                </p>
            </div>
        </div>
    </aside>

    

    <script>
        window.rootPath = "../../";
        window.currentCrate = "core";
    </script>
    <script src="../../main.js"></script>
    <script defer src="../../search-index.js"></script>
</body>
</html>