<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674742</guid>
        <pubDate>Thu, 23 Jun 2016 09:36:32 +0000</pubDate>
        <title>Многопоточное заполнение вектора без unsafe в Rust</title>
        <link>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674742</link>
        <description><![CDATA[Vesper: не хватает знаний :( И думаю, что надо перенести название языка в основной заголовок, а то непонятно, то ли алгоритмический вопрос, то ли надо выбрать язык под задачу.]]></description>
        <author>Vesper</author>
        <category>Rust</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674199</guid>
        <pubDate>Mon, 20 Jun 2016 11:36:49 +0000</pubDate>
        <title>Многопоточное заполнение вектора без unsafe в Rust</title>
        <link>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674199</link>
        <description><![CDATA[OpenGL: Вот у меня не получилось - так и не придумал, как сказать потоку, который получит ссылку на slice - результат split_at_mut, сказать, что ссылка будет жива пока он работает. Может как-то с lifetime поиграться надо будет. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-06-20T11:42:49+00:00">20.06.16, 11:42</time></span></span><br>
PS: пробовал написать так (через split_first_mut, но это не принципиально :)):<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">fn start_one_thread(a : &amp;mut [i32], children : &amp;mut Vec&#60;thread::JoinHandle&#60;()&#62;&#62;)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;match a.split_first_mut()</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Some(val) =&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let mut x = val.0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;children.push(thread::spawn(move||</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*x = 42;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;start_one_thread(val.1, children);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;None =&#62; {}</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
Это не компилится. Ошибка не самая очевидная (я, если честно, толком и не понял, что он от меня хочет  :crazy: ), но, впрочем, я ожидал, что не скомпилится из-за лайфтаймов, так что особо не разбирался<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">main.rs:7:10: 7:25 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements [E0495]</div><div class="code_line">main.rs:7 &nbsp; match a.split_first_mut()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~~~~~~~~~~~</div><div class="code_line">main.rs:7:8: 7:9 note: first, the lifetime cannot outlive the expression at 7:7...</div><div class="code_line">main.rs:7 &nbsp; match a.split_first_mut()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^</div><div class="code_line">main.rs:7:8: 7:9 note: ...so that auto-reference is valid at the time of borrow</div><div class="code_line">main.rs:7 &nbsp; match a.split_first_mut()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^</div><div class="code_line">main.rs:7:8: 7:27 note: but, the lifetime must be valid for the method call at 7:7...</div><div class="code_line">main.rs:7 &nbsp; match a.split_first_mut()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~~~~~~~~~~~~~~~</div><div class="code_line">main.rs:7:8: 7:9 note: ...so that method receiver is valid for the method call</div><div class="code_line">main.rs:7 &nbsp; match a.split_first_mut()</div></ol></div></div></div></div><br>
Если меняю первый аргумент на a : &amp;&#39;static mut [i32], то функция компилится, но, понятно, не получается её вызвать - переданный slice static-ом не является. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2016-06-20T11:47:14+00:00">20.06.16, 11:47</time></span></span><br>
Вообще, в старых версиях был thread::scoped. Вот если я правильно понял концепцию borrowing и lifetime, то с его помощью задача бы легко решилась.]]></description>
        <author>OpenGL</author>
        <category>Rust</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674165</guid>
        <pubDate>Mon, 20 Jun 2016 06:23:38 +0000</pubDate>
        <title>Многопоточное заполнение вектора без unsafe в Rust</title>
        <link>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674165</link>
        <description><![CDATA[Vesper: Почитал немного про split_at_mut, думаю, можно именно поделить, можно ещё с chunks_mut как я понимаю, тогда, если раздавать по куску вектора, должна быть потоковая безопасность.]]></description>
        <author>Vesper</author>
        <category>Rust</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674016</guid>
        <pubDate>Fri, 17 Jun 2016 18:40:39 +0000</pubDate>
        <title>Многопоточное заполнение вектора без unsafe в Rust</title>
        <link>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3674016</link>
        <description><![CDATA[OpenGL: Про такой способ я не подумал. Но в любом случае это не настолько интересно, как стандартный &quot;разбить вектор на n частей, каждую часть отдать своему потоку&quot;, который, собственно, я и попытался изначально написать. Думал, удастся подшаманить с каким-нибудь split_at_mut - не получилось. Вот и стало интересно - это я не осилил, или реально это делается только с unsafe?]]></description>
        <author>OpenGL</author>
        <category>Rust</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3673994</guid>
        <pubDate>Fri, 17 Jun 2016 14:36:53 +0000</pubDate>
        <title>Многопоточное заполнение вектора без unsafe в Rust</title>
        <link>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3673994</link>
        <description><![CDATA[Vesper: событиями и управляющим потоком? Т.е. заполняет один, но данные поступают от нескольких. Не устраивает?]]></description>
        <author>Vesper</author>
        <category>Rust</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3673854</guid>
        <pubDate>Thu, 16 Jun 2016 12:39:46 +0000</pubDate>
        <title>Многопоточное заполнение вектора без unsafe в Rust</title>
        <link>https://forum.sources.ru/index.php?showtopic=409005&amp;view=findpost&amp;p=3673854</link>
        <description><![CDATA[OpenGL: Можно ли сделать сабж? Нагуглил решение со сторонними библиотеками или с помощью unsafe. Можно ли это сделать, не пользуясь ни первым, ни вторым, и, разумеется, без блокировок?]]></description>
        <author>OpenGL</author>
        <category>Rust</category>
      </item>
	
      </channel>
      </rss>
	