Re: Bitfields always atomic? Other way to store attributes? - Mailing list pgsql-sql

From Owen Jacobson
Subject Re: Bitfields always atomic? Other way to store attributes?
Date
Msg-id 144D12D7DD4EC04F99241498BB4EEDCC274CE8@nelson.osl.com
Whole thread Raw
In response to Bitfields always atomic? Other way to store attributes?  (Bryce Nesbitt <bryce1@obviously.com>)
List pgsql-sql
TJ O'Donnell wrote:

> > If I have two threads modifying the same "bit" field:
> >     thread1=> update table set bf=bf | '01000'
> >     thread2=> update table set bf=bf | '10000'
> > Will this operation always be safe (e.g. result in bf='11000')?  Or
>
> Won't this always result in bf='11xxx', depending on the
> original values of bf?

Not even.  Consider:

thread1=> update table set bf=bf | '01000'
thread3=> update table set bf=bf & '10111'
thread2=> update table set bf=bf | '10000'

Now you get bf=10xxx.

They're thread safe in that all transformations will be applied as-if serially, so no bit sets or unsets will be lost,
butyou can't guarantee that another client won't interfere with the results. 


pgsql-sql by date:

Previous
From: "TJ O'Donnell"
Date:
Subject: Re: Bitfields always atomic? Other way to store attributes?
Next
From: Achilleus Mantzios
Date:
Subject: Flight numbers data