proper way to use memory barriers in userspace?

From: Chris Friesen
Date: Wed Nov 12 2003 - 11:07:21 EST



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


--
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: cfriesen@xxxxxxxxxxxxxxxxxx

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/