https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112015-12-28T18:13:03ZRuby Issue Tracking SystemRuby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=558182015-12-28T18:13:03ZEregon (Benoit Daloze)
<ul></ul><p>Why not create your own Mutex and store it in a constant at load time?<br>
Thread.exclusive could cause accidental contention because it is obviously global for all uses.</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=558202015-12-28T18:17:18ZEregon (Benoit Daloze)
<ul></ul><p>Also in this particular case, it seems relying on <code>require</code> being thread-safe would be good enough for ensuring a single initialization.</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=558242015-12-28T21:43:46Zbascule (Tony Arcieri)bascule@gmail.com
<ul></ul><p>Is a single-threaded require actually a <em>guarantee</em> of every Ruby VM?</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=558272015-12-28T22:42:31Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>I agree with Tony that Thread.exclusive still has uses. Was there some discussion on deprecating it?</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=558502015-12-29T20:01:48Zbascule (Tony Arcieri)bascule@gmail.com
<ul></ul><p>I received a PR to my project to "add Ruby 2.3 support" (via an inline Mutex) and I think it illustrates the problem:</p>
<p><a href="https://github.com/cryptosphere/rbnacl/pull/127" class="external">https://github.com/cryptosphere/rbnacl/pull/127</a></p>
<p>This doesn't really help, and I guess to make the warning message go away I need to just remove Thread.exclusive</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=558542015-12-29T22:58:04Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>This use of <code>Thread.exclusive</code> seems nonsense.<br>
<a href="https://github.com/cryptosphere/rbnacl/commit/25444979d161fa0f02a61a5003768c2173cfa2ee" class="external">https://github.com/cryptosphere/rbnacl/commit/25444979d161fa0f02a61a5003768c2173cfa2ee</a></p>
<p>While <code>Thread.exclusive</code> stops all other threads in 1.8 and earlier, it just blocks other threads which also calling it.<br>
If no other threads calls it, it is useless.</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=558762015-12-30T12:29:12ZEregon (Benoit Daloze)
<ul></ul><p>Tony Arcieri wrote:</p>
<blockquote>
<p>Is a single-threaded require actually a <em>guarantee</em> of every Ruby VM?</p>
</blockquote>
<p>Not single-threaded, but each file should be loaded at most once.<br>
Single require per file/path is certainly highly desirable,<br>
otherwise you may load the same file twice.<br>
It's also a lot easier to make it thread-safe than autoload IMHO.</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=559722016-01-05T17:17:04Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>This use of <code>Thread.exclusive</code> seems nonsense.<br>
<a href="https://github.com/cryptosphere/rbnacl/commit/25444979d161fa0f02a61a5003768c2173cfa2ee" class="external">https://github.com/cryptosphere/rbnacl/commit/25444979d161fa0f02a61a5003768c2173cfa2ee</a></p>
<p>While <code>Thread.exclusive</code> stops all other threads in 1.8 and earlier, it just blocks other threads which also calling it.<br>
If no other threads calls it, it is useless.</p>
</blockquote>
<p>That's the point; no two threads can call init via this code at the same time.</p>
<p>Of course, require's guarantee of "only once" would do the same thing here.</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=616252016-11-22T18:48:04Zjrochkind (jonathan rochkind)jonathan@dnil.net
<ul></ul><p>I came here cause I was curious why Thread.exclusive was deprecated, and didn't find an answer!</p>
<p>But for anyone else curious about the answer to Tony's original question (Tony has probably long since figured it out), I think you can <em>create</em> the Mutex at 'load time', to make sure you only have one? I <em>think</em> you can safely replace all uses of Thread.exclusive with something like this:</p>
<pre><code>class RbNaCl::NaCl
@init_mutex = Mutex.new
class << self
def init_mutex
@init_mutex
end
end
# all the rest of the definition....
end
# no more: Thread.exclusive { RbNaCl::NaCl.sodium_init }
RbNaCl::NaCL.init_mutex.synchronize { RbNaCl::NaCl.sodium_init }
# Or of course you could include the mutex.synchronize inside the `sodium_init` implementation,
# which would probably make more sense.
</code></pre> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=616602016-11-25T03:41:32Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>I feel that Thread.exclusive is too big a primitive to merely initialize a mutex at a process startup. We could perhaps introduce pthread_once_t analogous more fine-grained light-weight control structure that does the job.</p>
<p>P.S. we have /#{@mutex=Mutex.new}/o, so we already have such thing, to some extent at least.</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=617092016-11-25T09:21:34Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p><a href="mailto:shyouhei@ruby-lang.org" class="email">shyouhei@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>P.S. we have /#{@mutex=Mutex.new}/o, so we already have such thing, to some extent at least.</p>
</blockquote>
<p>Awesome, ROFL; you almost made me choke on my food!</p>
<p>Yes, //o is awesome, but this really takes the cake.</p>
<p>Carry on :)</p> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=887912020-11-27T02:45:46ZDorisWooky (DorisWooky DorisWooky)
<ul><li><strong>Tracker</strong> changed from <i>Misc</i> to <i>Feature</i></li><li><strong>Project</strong> changed from <i>Ruby master</i> to <i>14</i></li><li><strong>Subject</strong> changed from <i>Why was Thread.exclusive deprecated?</i> to <i>Gain Position cuddy</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88791/diff?detail_id=58396">diff</a>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=887922020-11-27T03:15:43Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Feature</i> to <i>Misc</i></li><li><strong>Project</strong> changed from <i>14</i> to <i>Ruby master</i></li><li><strong>Subject</strong> changed from <i>Gain Position cuddy</i> to <i>Why was Thread.exclusive deprecated?</i></li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=887932020-11-27T03:19:02Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88793/diff?detail_id=58400">diff</a>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=888192020-11-27T21:54:27ZJiceEmbelmlew (JiceEmbelmlew JiceEmbelmlew)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88819/diff?detail_id=58419">diff</a>)</li><li><strong>Tracker</strong> changed from <i>Misc</i> to <i>Feature</i></li><li><strong>Project</strong> changed from <i>Ruby master</i> to <i>14</i></li><li><strong>Subject</strong> changed from <i>Why was Thread.exclusive deprecated?</i> to <i> urcns</i></li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=888292020-11-29T23:36:21Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Feature</i> to <i>Misc</i></li><li><strong>Project</strong> changed from <i>14</i> to <i>Ruby master</i></li><li><strong>Subject</strong> changed from <i> urcns</i> to <i>Why was Thread.exclusive deprecated?</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88829/diff?detail_id=58429">diff</a>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=890162020-12-08T20:28:21ZJamesReots (JamesReots JamesReots)
<ul><li><strong>Tracker</strong> changed from <i>Misc</i> to <i>Feature</i></li><li><strong>Project</strong> changed from <i>Ruby master</i> to <i>14</i></li><li><strong>Subject</strong> changed from <i>Why was Thread.exclusive deprecated?</i> to <i>Proven traffic exchange traftop</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/89016/diff?detail_id=58506">diff</a>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=890182020-12-08T20:54:02Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Tracker</strong> changed from <i>Feature</i> to <i>Misc</i></li><li><strong>Project</strong> changed from <i>14</i> to <i>Ruby master</i></li><li><strong>Subject</strong> changed from <i>Proven traffic exchange traftop</i> to <i>hy was Thread.exclusive deprecated?</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/89018/diff?detail_id=58511">diff</a>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=891812020-12-12T01:48:58ZHermanLEd (HermanLEd HermanLEd)
<ul><li><strong>Tracker</strong> changed from <i>Misc</i> to <i>Feature</i></li><li><strong>Project</strong> changed from <i>Ruby master</i> to <i>14</i></li><li><strong>Subject</strong> changed from <i>hy was Thread.exclusive deprecated?</i> to <i>opg-vostorg</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/89181/diff?detail_id=58614">diff</a>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=892742020-12-17T09:09:58Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Feature</i> to <i>Misc</i></li><li><strong>Project</strong> changed from <i>14</i> to <i>Ruby master</i></li><li><strong>Subject</strong> changed from <i>opg-vostorg</i> to <i>Why was Thread.exclusive deprecated?</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/89274/diff?detail_id=58671">diff</a>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=897982021-01-06T07:48:00ZRobertjoise (Robertjoise Robertjoise)
<ul><li><strong>File</strong> <i>476.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=900002021-01-19T02:05:51Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>476.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=900212021-01-19T19:36:01ZGrona (Grona Grona)
<ul><li><strong>File</strong> <i>216.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=900282021-01-20T09:23:36ZGrona (Grona Grona)
<ul><li><strong>File</strong> <i>256.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=900682021-01-23T16:15:22ZRobertTougs (RobertTougs RobertTougs)
<ul><li><strong>File</strong> <i>122.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=900962021-01-26T05:10:06Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>216.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=900972021-01-26T05:10:10Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>256.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=900982021-01-26T05:10:14Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>122.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=903362021-02-11T00:43:49ZgendiamVary (gendiamVary gendiamVary)
<ul><li><strong>File</strong> <i>256.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=903382021-02-11T01:32:01Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>256.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=903712021-02-13T23:19:18ZWalterroowl (Walterroowl Walterroowl)
<ul><li><strong>File</strong> <i>359.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=903722021-02-13T23:32:06Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>359.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=905352021-02-21T02:39:36ZAndrewmuh (Andrewmuh Andrewmuh)
<ul><li><strong>File</strong> <i>270.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=905992021-02-26T00:11:59Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>270.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907132021-03-02T14:24:00Zatrox (atrox atrox)
<ul><li><strong>File</strong> <i>231.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907202021-03-02T20:13:53Zatrox (atrox atrox)
<ul><li><strong>File</strong> <i>228.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907242021-03-03T01:10:52Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>231.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907252021-03-03T01:10:55Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>228.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907472021-03-05T09:23:24ZJameshaivy (Jameshaivy Jameshaivy)
<ul><li><strong>File</strong> <i>581.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907482021-03-05T10:22:24Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>581.gif</i></del>)</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907612021-03-05T22:01:40Zhen (hen hen)
<ul><li><strong>File</strong> <i>29.gif</i> added</li></ul> Ruby master - Misc #11904: Why was Thread.exclusive deprecated?https://redmine.ruby-lang.org/issues/11904?journal_id=907752021-03-06T11:53:10Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>File</strong> deleted (<del><i>29.gif</i></del>)</li></ul>