Skip to content

Protect raw Ptr (interior mutability) in static/dynamic effects #251

Answered by arybczak
ruifengx asked this question in Q&A
Discussion options

You must be logged in to vote

However, from my understanding of the library, when concurrency is used somewhere in the effect stack, StaticReps are shared among children threads, which would result in race conditions.

Yes, if you use evalStaticRep. But if you look at its definition:

evalStaticRep e m = unsafeEff $ \es0 -> do
  inlineBracket
    (consEnv e dummyRelinker es0)
    unconsEnv
    (\es -> unEff m es)

It passes to consEnv a dummyRelinker that does nothing. You can use this definition inline in your effect, but pass a custom relinker that will either make a copy of the data Ptr points or if you want to forbid cloning the effect, you can just use the error call in the relinker. That will just give you an er…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@ruifengx
Comment options

@ruifengx
Comment options

@ruifengx
Comment options

@arybczak
Comment options

@ruifengx
Comment options

Answer selected by ruifengx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants