Skip to content

Mark newSingle/FixedThreadPoolContext as obsolete, document the reason #669

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

Merged
merged 1 commit into from
Oct 8, 2018

Conversation

elizarov
Copy link
Contributor

@elizarov elizarov commented Oct 6, 2018

* The will be replaced by another mechanism in the future.
  See #261 for details.
* The proposed replacement is to use the standard java API:
  Executors.newSingleThreadExecutor/newFixedThreadPool
  and convert to dispatcher via asCoroutineDispatcher() extension.
@elizarov elizarov requested a review from qwwdfsad October 6, 2018 14:14
@Dico200
Copy link

Dico200 commented Oct 6, 2018

I do not think that singleThreadContext should be deprecated and phased out. I think its functionality should remain a part of the API.

This is because limiting concurrent invocation of some set of methods/code to 1, is not the same as limiting it to one specific thread. Somewhere, you or someone else mentioned that it would break code if it uses ThreadLocal, however, I would hope that use case is not very common, as that should be unnecessary when there's just one thread already.

The problem I see is with regular mutable fields/properties not updating immediately on other threads unless they are volatile. The limitedThreadContext does permit access from various threads, even if it's only one at the same time. If the thread changes, field reads from the new thread might be outdated.

While the replacements you suggest are appropriate, I think there should be an option within the API that does the same as the current newSingleThreadContext. Whether that's by keeping it as is or creating an alternative, doesn't matter for this argument.

P.S. A test checking for this issue might be appropriate.

@elizarov
Copy link
Contributor Author

elizarov commented Oct 6, 2018

@Dico200 Have you checked out issue #261? It explain the solution to the same problem (limiting # of threads), but without actually creating a separate thread pool (that would need to be disposed of) for that.

@Dico200
Copy link

Dico200 commented Oct 6, 2018

@elizarov Yes, what I said was in light of the change proposed in #261.

I checked it again and I noticed I skimmed past these words a bit too quickly:

... some code in the wild that assumed that everything working in newSingleThreadContext was indeed happening in the single instance of Thread...

I missed the part with "in the single instance of Thread", which is the use case I describe.

However, I don't see anyone suggesting that it should stay for the reason I specified.

@qwwdfsad
Copy link
Collaborator

qwwdfsad commented Oct 8, 2018

Let's move the discussion to #261.
I will merge this PR as it doesn't break anything and will not be removed in 1.0.0.

@qwwdfsad qwwdfsad merged commit f5126d0 into develop Oct 8, 2018
@qwwdfsad qwwdfsad deleted the new-thread-obsolte branch March 1, 2019 12:59
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.

3 participants