Skip to content
0:00 / 0:00

#ffi#c#ghc

The Haskell Unfolder Episode 36: concurrency and the FFI

Well-Typed

3.4K subscribers • 14 videos on Hallway

YouTube
  • Recommended by 2 people: 1 on Lobsters and 1 in engineering communities.

Intermediate. Assumes working knowledge.

1.5K views1 year ago2 recommendations

Programming languagesSystems programmingHaskellConcurrency and parallelismPerformance and optimization

An explanation of safe versus unsafe foreign function imports in Haskell and how they interact with GHC's runtime and concurrency.

There are two primary ways to import C functions in Haskell: "unsafe" and "safe". We will first briefly recap what this means: `unsafe` functions are fast but cannot call back into Haskell, `safe` functions are much slower but can. As we will see in this episode, however, there are many more differences between `unsafe` and `safe` functions, especially in a concurrent setting. In particular, `safe` functions are not always safer!

Why it's here

2 people recommend this

What people say. Recommended for its clear explanation of Haskell's FFI behavior under concurrent workloads.

u/kosmikusin r/haskell • Recommends

The Haskell Unfolder Episode 36: concurrency and the FFI

Hecateon Lobsters • Recommends

The Haskell Unfolder Episode 36: concurrency and the FFI

u/massudawin r/haskell • Mentions

On “Question regarding GHC green threads”

Depends if those are ffi calls or just using blocking io via io manager. Also there is no way to limit number number of green threads, there will be as many as you call forkIO. This might be useful in understanding: link to this video

u/TechnoEmpressin r/haskell • Mentions

On “Should FFI always be IO?”

Side-idea but you could absolutely use a finer-grained effect system (like effectful) to create an `FFI` effect that corresponds semantically to your definition of "I do outside calls and they are / are not safely retryable and are / are not interruptible" (watch link to this video for more interesting details)