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

Multi_channel: allow more than one instance per program with different configurations #50

Merged
merged 21 commits into from
Dec 22, 2021

Conversation

edwintorok
Copy link
Contributor

Multi_channel had shared global state in the form of dls_new_key which caused ids assigned by one multichannel to be used by another (possibly smaller channel), resulting in out-of-bounds array indexing.
One possible way to fix this is to remove the global key, and use a per-channel key.

The key here also has some mutexes and conditional variables that you probably don't want shared across different multi-channels.

Draft PR, because there must've been a reason why this was a shared global variable to begin with.

Appears to fix #43 on my machine

edwintorok and others added 2 commits October 10, 2021 23:50
There can be multiple multi_channel (or indeed pool) instances active at
the same time, each with a different configuration.
We cannot necessarily safely reuse any IDs issued by one channel on
another channel, so ensure that we use a unique key per channel by
allocating it together with the channel.

Signed-off-by: Edwin Török <[email protected]>
@kayceesrk
Copy link
Contributor

kayceesrk commented Oct 11, 2021

@ctk21 is the right person to look at this one.

Copy link
Contributor

@ctk21 ctk21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no special reason for the channel domain state to be global. Indeed it is reasonable and an improvement to allow multiple pools!

The only concern that comes to mind is if we need to be stronger about preventing tasks being accidentally used between two pools. For example Domain A1 is in pool A but does an await on a task executing in pool B, that could be a source of bugs in the absence of an argument for why it works.

if dls_state.id >= 0 then dls_state
let dls_state = Domain.DLS.get mchan.dls_key in
if dls_state.id >= 0 then begin
assert (dls_state.id < Array.length mchan.channels);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert is going to execute every time which is sad, but I guess it can stay if you are strongly in favour.

@edwintorok
Copy link
Contributor Author

edwintorok commented Oct 11, 2021 via email

@edwintorok
Copy link
Contributor Author

#51 I'll rebase my PR once this is in, and think about what needs to be done to run multiple pools safely.

@kayceesrk
Copy link
Contributor

@Sudha247 Perhaps this is relevant to the Lwt_domain work.

abbysmal and others added 5 commits October 27, 2021 15:10
…aml-cache

Use a random number as the cache prefix to disable cache in CI
…_4.12+domains+effects_as_cache_key

use last 4.12+domains+effects hash as the cache-key
Make domainslib build/run with OCaml 5.00 after PR #704
@avsm avsm marked this pull request as ready for review November 1, 2021 15:57
@kayceesrk
Copy link
Contributor

Hi @edwintorok, Jan has created a PR that fixes the conflicts to your branch #58 (comment). Would you prefer if Jan sends a PR to your unique-key branch, which you can merge, after which this PR can be merged?

The test relies on reading backtrace contents, so we need to ensure that
backtraces are on (by default they'd be off).

Signed-off-by: Edwin Török <[email protected]>
@edwintorok
Copy link
Contributor Author

Thanks a lot @jmid, I've updated this PR to include your changes.
I've also fixed the test/backtrace.ml unit test which was failing locally (unrelated to this PR, but I like all unit tests to pass).

@kayceesrk kayceesrk merged commit 59ee895 into ocaml-multicore:master Dec 22, 2021
@kayceesrk
Copy link
Contributor

LGTM. Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

possible bug in Task.pool management
9 participants