Skip to contentSkip to conversation

proper way to use memory barriers in userspace?

DISCUSSION Chris Friesen 1 participant 1 message Nov 12, 2003

lore
Share & tools
lore
#0 lore raw

I've got a number of processes on an SMP box that communicate via shared memory. I want to avoid locking, so I am considering using flags and memory barriers.

However, I've run into a snag--the barriers are buried within __KERNEL ifdefs. Is the proper way to handle this just to copy/paste into userspace?

Also, I wanted to double-check that my barrier usage was correct. The data consists of a flag indicating whether a scan was done, and the results of the scan. The main may check the flag at any time, so I want to make sure that there is no way that it can see the flag as set but have inconsistant data in the results field. My plan was to do the following:

main process:
clear flag
mb
kick other process
wait (may be kicked by others here too)
for all other processes:
if flag set
check data

other process:
wait to be kicked
do scan
update results
wmb
set flag
mb
kick main

Is this the proper way to do it?

Thanks,

Chris

Signature · 4 lines
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: [email protected]