[prev in list] [next in list] [prev in thread] [next in thread] 

List:       hpux-cxx-dev
Subject:    Re: CXX-DEV: #pragma _CNX critical_section etc.
From:       "Randall P. Meyer" <meyer () rsn ! hp ! com>
Date:       1999-02-18 22:02:33
[Download RAW message or body]


> +O3 +Oparallel seems to be OK. So what happens if I have no optimizations
> enabled or a lower optimization level - is the code still thread-safe?
> How lightweight are these locks in comparison with pthread_mutexes (which is
> what we're trying to avoid)?

If you haven't explicitly created multiple threads, and are at opt level
+O2 or lower, you will be running with only one thread, so you will be
thread-safe by default.

If you've explicitly created multiple threads, then you will need to 
make your code thread-safe.  If the threads were spawned using pthreads,
you must use the pthreads mutexes.

If you are going parallel using cpslib, then you can use cps_mutex_lock/
cps_mutex_unlock (which, b.t.w. are simply aliases for __cps_begin_critical/
__cps_end_critical).  These are faster than the pthreads mutexes because
they use spin locks to wait rather than suspending a waiting thread.
If you are *really sure* you know what you are doing, you could use
the low-level m_lock/m_unlock, which are slightly faster than cps_mutex_lock/
cps_mutex_unlock, but do absolutely no error checking at all.

-- Randy

> 
> Kit
> 
> -----Original Message-----
> From: Terry Caracuzzo [mailto:caracuzz@rsn.hp.com]
> Sent: Thursday, February 18, 1999 1:16 PM
> To: Ewbank, Kit
> Subject: RE: CXX-DEV: #pragma _CNX critical_section etc.
> 
> 
> hi, i feel your pain, you need +O3 +Oparallel :-(
> 
> terry
> 
> this is for c, for C++, you have to explicitly invoke the
> cps_ functions, since the #pragma approach is only in the c
> compilers currently
> 
> > Using HP C/HP-UX  Version A.11.00 (EXTPAK 9806).
> > My exact assembler source is (cc -c -S):
>  _________________________________________________________________
>  To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
>     with the message UNSUBSCRIBE cxx-dev
>  _________________________________________________________________
> 

 _________________________________________________________________
 To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
    with the message UNSUBSCRIBE cxx-dev
 _________________________________________________________________

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic