Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,333
    • Issues 4,333
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 371
    • Merge Requests 371
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #3745

Closed
Open
Opened Dec 11, 2009 by gchrupala@trac-gchrupala

Non-deterministic behavior with FFI

I have a simple perceptron learning algorithm in C++ which I am calling from Haskell via FFI. Most of the time it works perfectly, but occasionally the results it produces are not the expected. It seems to happen more often if there is another memory/cpu intensive process running on the machine.

The same never happens when I call the same function from C++, which seems to indicate the problem is related to GHC.

I attach a simplified extract of the code which will show the problem.

I included:

  • c_perceptronmodel.cpp, c_perceptronmodel.h : C++ implementation
  • test.hs : Haskell program which calls the C++ function via FFI
  • test.cpp : Equivalent C++ program which calls the same C++ function
  • run.sh : shell script which will repeatedly run a program and check if any consecutive two runs produce different results
  • train : data file which the programs process

I compiled using GHC 6.10.4 like this:

ghc-6.10.4  --make -O2 -o test-ghc-6.10.4 test.hs c_perceptronmodel.cpp -lstdc++

To see the problem execute:

./run.sh ./test-ghc-6.10.4
Trac metadata
Trac field Value
Version 6.10.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (FFI)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture Unknown/Multiple
Assignee
Assign to
6.12.2
Milestone
6.12.2
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#3745