Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ractor#receive supports filtering #3862

Merged
merged 1 commit into from
Dec 16, 2020
Merged

Conversation

ko1
Copy link
Contributor

@ko1 ko1 commented Dec 8, 2020

@marcandre
Copy link
Member

marcandre commented Dec 8, 2020

In ractor_receive_block where there is b->type = basket_type_ref, don't we need to wake any sleeping thread/fiber (in the current Ractor) doing a Ractor.receive?

The following deadlocks:

assert_equal ':ok', %q{
  r = Ractor.new do
    t = Thread.new { Ractor.receive { sleep(0.2); _1 == :foo }  }
    sleep(0.1) # let thread receive first
    Ractor.receive { sleep(0.2); _1 == :bar }
    t.join
    :ok
  end
  r << :bar << :foo
  r.take
}

@ko1
Copy link
Contributor Author

ko1 commented Dec 8, 2020

Unfortunately, all synchronization methods (receive, yield, take) doesn't support Threads because they share the synchronization data structures. It in my TODO list.

@marcandre
Copy link
Member

Ah, ok, good to know.

@ko1 ko1 force-pushed the ractor_filtered_receive branch 2 times, most recently from 87f06a1 to 5f75b0e Compare December 8, 2020 16:55
Instead of Ractor.receive, Ractor.receive_if can provide a pattern
by a block and you can choose the receiving message.

[Feature #17378]
@ko1 ko1 merged commit a9a7f4d into ruby:master Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants