2

One of my students is having a severe problem with their project (assignment is: http://turing.plymouth.edu/~kgb1013/?course=4310&project=0). They (and I) are getting a weird error when compiling with my test file, testSemaphore.chpl, available at: http://turing.plymouth.edu/~kgb1013/4310/semaphoreProject/testSemaphore.chpl . The error is this:

$CHPL_HOME/modules/standard/IO.chpl:3038: error: sync variables cannot currently be written - apply readFE/readFF() to those variables first

I've had them remove the body of all of their methods, but they're still getting the error. Here is the body of their code:

use Time;

class Semaphore {
    var gate1$ : sync int;

    //Constructor
    proc Semaphore(){
    }

    //secondary Constructor
    proc Semaphore(givenTokens : int){
    }

    //returns the number of tokens available
    proc getNumTokens() : int {
        return 1;
    }

    //gives out a token
    proc p() {

    }

    //returns a token
    proc v() {
    }

}

Why are they getting this error?

Kyle
  • 554
  • 3
  • 10
  • 1
    What version of Chapel are you using? For clarification, does the body of code posted produce the error for you? It is compiling and running for me on the `master` branch and `1.16.0` – ben-albrecht Feb 26 '18 at 16:28
  • 1
    Sorry, I had misinterpreted the code provided. I have reproduced the error now. – ben-albrecht Feb 26 '18 at 16:34

1 Answers1

4

Sorry you're having trouble! It turns out that some of this would be better as a GitHub issue on the Chapel project, but let me first explain what's happening.

The class Semaphore includes a sync variable field. Meanwhile, the default implementation for writing a class is to write each field. So the error message in IO.chpl is trying to say that it doesn't have a reasonable way of outputting a sync variable. E.g.

var x: sync int;
writeln(x);

gives the same error. I think it would be reasonable to open up a GitHub issue on the Chapel project about how inscrutable this error is (and how it doesn't report a line number that is useful to you). Note that I personally used chpl testSemaphore.chpl --print-callstack-on-error to better understand the error - it often helps to add --print-callstack-on-error when you get an error referring to an internal/standard module.

Now, as for the assignment, there are two ways to resolve it:

  1. Adjust testSemaphore.chpl to not print out the semaphore representation in 'writeln' calls. I commented out both writelns starting with "Testing that" and got it to compile.
  2. Adjust the class Semaphore to include a writeThis to replace the compiler-generated write-each-field default, as below:

Here is an example of such a writeThis (see also The readThis, writeThis, and readWriteThis methods )

class Semaphore {
  var gate1$ : sync int;
  // Other methods as before
  proc writeThis(f) {
    f <~> "sync semaphore";
  }
}
mppf
  • 1,820
  • 9
  • 9
  • 1
    Oh, it's because he didn't add a writeThis method! Got it! I added a bit to the project description to make sure people skip it less often. – Kyle Feb 26 '18 at 19:04