- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Atomic semaphore in 'C' on HP UX
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2002 09:20 AM
тАО04-05-2002 09:20 AM
Atomic semaphore in 'C' on HP UX
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2002 09:51 AM
тАО04-05-2002 09:51 AM
Re: Atomic semaphore in 'C' on HP UX
I don't quite understand, I used the semop() system call in many flavors of UNIX (both SystemV and BSD based) for over 20 years and it works like a charm and does atomic operations. Dijkstra would be most unhappy if his "P" and "V" semaphores were not atomic.
Tha man page for semop is quite clear and gives examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2002 10:51 AM
тАО04-05-2002 10:51 AM
Re: Atomic semaphore in 'C' on HP UX
int sem;
tas(int *sem)
{
if (sem)
return(0);
else
return(++*sem);
}
clear(int *sem)
{
*sem = 0;
}
However the above must be atomic.
Examples: Motorolla and TI use "tas" as function name.
AIX uses "cs" (for check & set?).
I assume HP UX has something similar but man pages don't have either of the above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2002 01:56 PM
тАО04-05-2002 01:56 PM
Re: Atomic semaphore in 'C' on HP UX
There are also some mechanisms for sychronizing threads like lock_gate() and cond_lock_gate() but since your project is K & R C, you are going to have a difficult time using them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2002 04:22 PM
тАО04-05-2002 04:22 PM
Re: Atomic semaphore in 'C' on HP UX
Test and set is what I need, but if not there then I guess I don't have it.
I have used in the past for some systems (that also do not have TAS) my own routines (stolen from a KR textbook) which only have one requirement:
int sem;
sem++;
I need the "sem++" to be atomic. In some systems this is atomic on int and not char, some it is on char and not int, one it is atomic on long! Go figure.
Does anyone know if char, int,
or long increments/decrements
are atomic on HP UX???
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2002 12:57 PM
тАО04-06-2002 12:57 PM
Re: Atomic semaphore in 'C' on HP UX
If you are serious about needing semaphores and you can't use the normal semaphores then your only real alternative is to use the libpthread functions (e.g. pthread_mutex_lock() and pthread_mutex_trylock()). Man pthread for details. These are quite fast and are intended for your purposes. You will almost cerainly have to make ANSI/C calls withing this code section but these can simply be wrappers for your K&R code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2002 04:49 AM
тАО04-07-2002 04:49 AM
Re: Atomic semaphore in 'C' on HP UX
What we used to do "way back when" is write your routines in C, then use the C compiler to generate assembly code. Manually edit the assembly, and add the instructions to clear interrupts (usually "cli", you'll have to look it up, as I haven't done this on HPUX/PA-RISC) so that the scheduler cannot interrupt the routine during execution. At the end of the routine, re-enable interrupts.
When you're done editing, assmebly the code, and use it as you would any C routine.
This always worked well for me, and is basically how the kernel does atomic operations.
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2002 12:46 AM
тАО04-08-2002 12:46 AM
Re: Atomic semaphore in 'C' on HP UX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2002 10:16 AM
тАО04-08-2002 10:16 AM
Re: Atomic semaphore in 'C' on HP UX
I found this hunting about the web:
PS Instruction "Test and Set"
An often-asked assembly language question for the PA-RISC architecture is the location of an atomic "test and set" instruction for
performance sensitive operations. The "load and clear" word short instruction can perform "test and set." The word must be on a 16-bit
boundary. See the "PA-RISC Architecture and Instruction Set" manual for information on how this instruction operates.
It appears from mucho sources that TAS does not exist but that load/clear can be used in assembler. Does anyone have any assembler code that I can link into my C code (after compiling) that performs the load and clear (and in an ideal world a test function)????
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-25-2002 10:05 AM
тАО09-25-2002 10:05 AM
Re: Atomic semaphore in 'C' on HP UX
;
; spin.s: Example assembly language routine for spinlock support.
;
.code
; .level 2.0W ; use this option for 64-bit assembly
.export load_and_clear,entry,priv_lev=3,rtnval=gr
.proc
load_and_clear
.callinfo no_calls
.enter
; create a 16 byte aligned pointer to the load+clear word area
addi 15,%arg0,%arg2 ; add 15 to pointer provided to round up
; Choose one of these statements and comment out the other:
depi 0,31,4,%arg2 ; mask off the lower 4 bits (32-bit version)
; depdi 0,63,4,%arg2 ; mask off the lower 4 bits (64-bit version)
; load and clear the spinlock. If locked, return 0
stbys,e 0,(%arg2) ; scrub cache; important for performance
ldcws (%arg2),%ret0 ; load and clear the spinlock word
nop ; 3 No-Op instructions; needed for older
nop ; HP-PA chips
nop
bv,n (%r2)
.leave
.procend