Path: utzoo!utgpu!water!watmath!clyde!ima!necntc!encore!paradis From: paradis@encore.UUCP (Jim Paradis) Newsgroups: comp.sys.encore Subject: Re: File buffers Keywords: Buffered file input Message-ID: <3435@encore.UUCP> Date: 4 Aug 88 18:04:32 GMT References: <585@cmx.npac.syr.edu> <2185@alliant.Alliant.COM> Reply-To: paradis@encore.UUCP (Jim Paradis) Distribution: na Organization: The Whizzo Chocolate Company Lines: 42 In article <2185@alliant.Alliant.COM> jeff@alliant.UUCP (Jeff Collins) writes: >Given the buffering syntax of stdio, there is really no way to do >what you want. The only suggestions that I would have would be to >use read(2)/write(2) directly (ie. eliminate the buffering). > > The other possible alternative is to change the stdio >libraries so that the buffers use shared memory. I wouldn't think >that this would be a trivial solution, and is probably not something >that you would want to do yourself - but it is an idea. Hi, Jeff! There IS a third way... it's not pretty, but it gets the job done without having to change the I/O libraries: (1) Create a region of shared memory that's at least BUFSIZ + sizeof(FILE) long. (2) After opening the file, copy the FILE object into the shared memory region, and refer to it ONLY by the shared-memory address from now on. (3) Use setbuf(3) to place the buffer associated with the FILE object into shared memory. (4) Put spinlocks around all of your stdio calls so that you don't accidentally step all over yourself. Note, of course, that this scheme has the {feature|bug} that this file object is COMPLETELY shared among all processes; therefore, if one process changes the state of the object (e.g. moves the file pointer), that change is seen by all other processes. Standard parallel programming practices apply; if you change the state of the object and a future operation depends on the state you produced (e.g. fseek followed by fread), then you must lock the ENTIRE section of code until such time as you no longer depend on the object having a particular state. -- Jim Paradis, Encore Computer (.signature undergoing renovations. Please pardon our appearance.)