Re: Something is wrong with my threads

Robert Klemme <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAM9pMnMxRz0YnSYQo=s46KSX2FoTDEHqUM0RzVupy3o0md7nCQ@mail.gmail.com>
On Thu, Apr 18, 2019 at 10:50 AM Andy Jones <[email protected]> wrote:
>
> > You don’t test race conditions by simulating non-deterministic conditions.
> > You test a race condition by deterministically faking the race collision.
>
> I rather thought that I was doing the latter.  I'm attempting to arrange for fifty threads to call a method at the same time.

But you are aware that this is not reliably possible no matter what
you attempt, are you?

> That in itself is not deterministic -- I can't guarantee to be successful in doing that every time, unfortunately, or I could just make two threads instead of fifty.  But I'm not "simulating a non-deterministic condition".  The condition is deterministic; if I manage to call the same method twice at exactly the same time, then there will always be a problem.  (Except the code uses a Mutex, so I'm testing that there is not one.)

I am not sure I am following here. What is the goal you want to achieve?

> > Or you design your code to not have the race condition at all (better).
>
> I have.  I've used a Mutex to eliminate the possibility of a race condition.  Now I need to test that that works.

A mutex guarantees that there are no two threads in the critical
section. You do not need to prove that it works that way. Others have
done that for you already. If you want to do something like that you
could do it like in the attached script.

Kind regards

robert

-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
p.rb (application/x-ruby, 357 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.