Return to BSD News archive
Newsgroups: comp.os.386bsd.questions Path: sserve!newshost.anu.edu.au!munnari.oz.au!constellation!osuunx.ucc.okstate.edu!moe.ksu.ksu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!math.ohio-state.edu!cs.utexas.edu!uunet!emba-news.uvm.edu!sadye.emba.uvm.edu!wollman From: wollman@sadye.emba.uvm.edu (Garrett Wollman) Subject: Re: A question about process synchronization... Message-ID: <1993Sep24.213943.19123@emba.uvm.edu> Keywords: messages, ipc, semaphores Sender: news@emba.uvm.edu Organization: University of Vermont, EMBA Computer Facility References: <27u625INNpn6@bonnie.tcd-dresden.de> Date: Fri, 24 Sep 1993 21:39:43 GMT Lines: 49 In article <27u625INNpn6@bonnie.tcd-dresden.de>, Alfredo Herrera <alf@bonnie.tcd-dresden.de> wrote: > The writer-reader-problem can be solved quite elegant and >efficient using the implentation of Dijkstra's semaphores on SYSV.4. ------------------------------------ typedef int sem[2]; int init_sem(sem *sema) { return pipe(*sema); } int destroy_sem(sem *sema) { close((*sema)[0]); return close((*sema)[1]); } void P(sem *sema) { char ch; while(read((*sema)[0], &ch, 1) != 1) ; } void V(sem *sema) { char ch; while(write((*sema)[1], &ch, 1) != 1) ; } ------------------------------------ Thanks to Jonathan Simon Kay for showing me this trick four years ago. Note that it works just fine with plain old Seventh Edition pipes. There was really no excuse for the sem* operations in SVR3; they always should have used named pipes instead. Proliferation of namespaces is evil. Now we should probably develop a shared memory interface that replaces SYSVSHM, but uses filesystem entities to name and manage the space. (Basically what we need is an mmap() version that only uses the vnode to name the memory space, rather than as a backing store, too.) -GAWollman -- Garrett A. Wollman | Shashish is simple, it's discreet, it's brief. ... wollman@emba.uvm.edu | Shashish is the bonding of hearts in spite of distance. uvm-gen!wollman | It is a bond more powerful than absence. We like people UVM disagrees. | who like Shashish. - Claude McKenzie + Florent Vollant