
#10296: Segfaults when using dynamic wrappers and concurrency -------------------------------------+------------------------------------- Reporter: bitonic | Owner: jme Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Runtime System | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2031 Wiki Page: | -------------------------------------+------------------------------------- Changes (by jme): * status: new => patch * differential: => Phab:D2031 Comment: In the example above, each call to `wrap` allocates a new stable pointer, which is then dereferenced when `call_fun` calls back into Haskell. Since the stable pointers are not freed, the table holding them is periodically enlarged (using `realloc()`). When one of these reallocations moves the table just as it is being read by another thread (to dereference a stable pointer), a segfault can occur. The fix provided by Phab:D2031 is rather simplistic: it eliminates the freeing of the old table during reallocation, thus ensuring the table can continue to be safely read. While this approach allows dereferences to remain lock-free, it clearly wastes space (roughly twice the memory is now required to hold the stable pointer table). If this is an issue, it should be relatively straightforward to eliminate the extra memory consumption without adversely affecting performance (albeit with some added complexity). Let me know if such an implementation would be preferable. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10296#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler