Thanks, Alexei, Xiao Feng,
This was helpful.
BTW, as far as I understand using mutexes, I need to protect reads as
well. If I use CAS for adding a new element, the list is always
consistent for reading from other threads without any protection.
On Wed, Apr 9, 2008 at 6:00 PM, Xiao-Feng Li <[EMAIL PROTECTED]> wrote:
> Right.
>
> To avoid the CAS loop, you can use Mutex.
>
> mutex_lock();
> //critical section;
> mutex_unlock();
>
> Thanks,
> xiaofeng
>
>
>
> On Wed, Apr 9, 2008 at 8:35 PM, Aleksey Shipilev
> <[EMAIL PROTECTED]> wrote:
> > IMHO here:
> >
> > 1. Using CAS infers using busy-loop, e.g. "we are trying until
> > operation succeed". You might tolerate spinning there by using PAUSE
> > instruction or some other way.
> > 2. How about "static int counter = 0; #define INC() counter++;"? It
> > will be done in runtime though.
> >
> > Thanks,
> > Aleksey.
> >
> >
> >
> > On Wed, Apr 9, 2008 at 3:57 PM, Alexei Fedotov <[EMAIL PROTECTED]> wrote:
> > > Hello folks,
> > > Could you please help?
> > >
> > > 1. Is it possible to add to a thread safe linked list using CAS
> > > without a busy loop?
> > >
> > > void add_site(LogSite* log_site) {
> > > LogSite** p_site_head = (LogSite**) &get_logger()->log_site;
> > > LogSite* old_value = *p_site_head;
> > > do {
> > > log_site->next = (LogSite*) old_value;
> > > (LogSite*) old_value = (LogSite*) apr_atomic_casptr((volatile
> > > void **) p_site_head,
> > > (void*) log_site, log_site->next);
> > > } while (old_value != log_site->next); // busy loop
> > > }
> > >
> > > 2. Is it possible to create an auto-increment macro within a
> > > compilation unit using C preprocessor?
> > >
> > > #define INC() ...
> > >
> > > INC() // == 1
> > > INC() // == 2
> > > ...
> > >
> > > Thank you for sharing your expertise.
> > > --
> > > With best regards,
> > > Alexei
> > >
> >
>
>
>
> --
> http://xiao-feng.blogspot.com
>
--
With best regards,
Alexei