From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu Date: Mon, 10 Jul 2000 09:57:05 +0000 From: Jakub Jermar Message-ID: <8kasmg$2k9e$1@news.vol.cz> Subject: [9fans] Kernel question: i386 test-and-set problem Topicbox-Message-UUID: d68bc282-eac8-11e9-9e20-41e7f4b1d025 Hi all, I've just been studying the 9 kernel and found something very weird. In /sys/src/9/pc/l.s, there is an assembly function called tas() that should provide its callers with an atomic test-and-set operation. This function is called, for instance, by lock() from taslock.c. The weird thing is that it looks as though this function only exchanged %eax and (%ebx) by XCHG instruction which is NOT atomic. The C source looks satisfied with it (I have no opportunity to try it, because I am not running Plan 9 - yet :-). By further searching, I found (in /sys/src/lithread/386cas.s... or something) a routine called cas(). This routine uses the proper 386 atomic instruction CMPXCHG. Well, what's going on? I'd expect all those C functions to call cas() instead of tas(). Mys second question is why cas() is not the only tas() (test-end-set) within the 386 part of the kernel. My last question is why the cas() is outside the kernel tree. Regards, Jakub Jermar