Thread-Safe FileStreams

Mark Guzdial guzdial at cc.gatech.edu
Mon Apr 6 20:37:31 UTC 1998


>>I've tried it from Squeak - the result is the same. However, "/dev/stdout"
>>is not considered to be a "regular" file. If you do the same with a usual
>>file handle, only the second write should show the effect. That is at
>>least what Squeak is doing if I try
>
>I tried Andreas' example under MacOS, and it worked just fine.  So, why
>does the below generate primitive fail errors? -- two of them, one on each
>close.
>EXAMPLE SNIPPED HERE
>Is it just because there are two processes accessing the same file?

I was curious enough about this that I actually generated the VM source
(kinda fun, actually!) and dug around in it.  The check for file validity
(which is called by the file close primitive) explicitly checks the
"sessionID."

int sqFileValid(SQFile *f) {
	return (
		(f != NULL) &&
		(f->file != NULL) &&
		(f->sessionID == thisSession));
}

But the session ID is set just once at startUp, not in every thread:

int sqFileInit(void) {
	/* Create a session ID that is unlikely to be repeated.
	   Zero is never used for a valid session number.
	   Should be called once at startup time.
	*/

	thisSession = clock() + time(NULL);
	if (thisSession == 0) thisSession = 1;	/* don't use 0 */
}

Now, I'm quite confused why I'm getting the primitive fails on close.  One
primitive fail makes sense -- the first one closed it, so the second one
probably has something as NULL.  But why both?

Mark

--------------------------
Mark Guzdial : Georgia Tech : College of Computing : Atlanta, GA 30332-0280
(404) 894-5618 : Fax (404) 894-0673 : guzdial at cc.gatech.edu
http://www.cc.gatech.edu/gvu/people/Faculty/Mark.Guzdial.html





More information about the Squeak-dev mailing list