From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,a3ae14aeae49226 X-Google-Attributes: gidfee84,public From: Aurel Balmosan Subject: Re: mutex between processes? Date: 1998/08/09 Message-ID: #1/1 X-Deja-AN: 379441657 X-Nntp-Posting-Host: 194.122.136.143 Sender: news@orga.com (News Administrator) References: <35C85511.E31EBB9E@brighttiger.com> <35CAC907.497400F4@orga.com> <35CB2911.61856927@brighttiger.com> <35CBBDEE.17958205@ne.mediaone.net> Organization: ORGA Kartensysteme GmbH Newsgroups: comp.unix.osf.osf1 Monty Brandenberg wrote: > Problems due to incorrect SMP algorithms are very difficult to debug. It is > much easier to do the research and get it right the first time.... >From this discusion I made following concept. Following structures are in the shared memory. Proc 1: spinlock, some data, current_accessed_item Proc 2: ItemTable: Item 1: index_to_the_real_item Item 2: .. RealItem: Item 1: (Some data depending on the item) Item 2: ... So now the proc 1 tries to access Item 1: - lock its spinlock - read real address of item1 from ItemTable - set the current_accessed_item to the found address - unlock its spinlock - read the data If a writer (there is only one at a time) want to change item 1 it do following: - lock global writer spinlock - alloc and set a new item in RealItem, - queue the old address of item 1 in a cleanup-queue. - write new address into item 1 in ItemTable - unlock global writer spinlock. Some server do following: - lock gloabal writer spinlock - get an item address out of cleanup-queue - unlock gloabal writer spinlock. - check if someone accesses this item currently. if yes put it again in the queue if no lock gloabal writer spinlock mark the item as reusable unlock gloabal writer spinlock. - continue The critical part is writing the current_accessed_item and the index_to_the_real_item. It must be guaranteed that after the unlock of the proc spinlock current_accessed_item has the correct value for any process on any processor. (How do I handle that?) For the index_to_the_real_item it is needed that the reader will allways get a valid (which may be old) address. I think that ATOMIC_EXCHANGE... can be used by the writer. (with or without _MB?) Bye, Aurel. -- Aurel Balmosan | Department SE-SW ORGA Kartensysteme GmbH | phone: +49 5254 991 824 An der Kapelle 2 | fax : +49 5254 991 749 33104 Paderborn, Germany | mailto:ab@orga.com