Volatile field use cases?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Volatile field use cases?

Jeremy Manson-2
Hi folks,

Some of us were talking off line about the ways in which people use
volatile fields.  They can be used for writing a variety of interesting
data structures, like non-blocking queues, but I have no idea how many
people are doing this.

I thought it might be interesting to ask the crowd here about the more
interesting ways in which you use volatiles.  Do you have something
fabulously interesting that you do?  Do you write non-blocking data
structures?  One thing I don't really know is if people ever write code
that relies on strong guarantees between more than one volatile field --
do you?

Basically, what are you folks using them to do?

All of this is by way of finding out what the impact of the JMM has
been, now that we are a couple of years down the line: seeing what works
and what doesn't, and laying out plans for future memory models.

Thanks,

                                        Jeremy
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Volatile field use cases?

Kevin Condon
I don't have any unique uses for volatiles to describe, but I think
this is an important topic.  When I started using Java back around
1999, the rumor was that volatile semantics were not reliable in all
JVM implementations and that the use of synchronized blocks was the
approach of choice.  The rumors were not incredibly well
substantiated, but it was enough that many of us put volatiles in the
closet.  That's a habit that I'm beginning to change with the new JMM,
and this kind of discussion could help to stimulate that change.

Regards,
Kevin

On 10/27/06, Jeremy Manson <[hidden email]> wrote:

> Hi folks,
>
> Some of us were talking off line about the ways in which people use
> volatile fields.  They can be used for writing a variety of interesting
> data structures, like non-blocking queues, but I have no idea how many
> people are doing this.
>
> I thought it might be interesting to ask the crowd here about the more
> interesting ways in which you use volatiles.  Do you have something
> fabulously interesting that you do?  Do you write non-blocking data
> structures?  One thing I don't really know is if people ever write code
> that relies on strong guarantees between more than one volatile field --
> do you?
>
> Basically, what are you folks using them to do?
>
> All of this is by way of finding out what the impact of the JMM has
> been, now that we are a couple of years down the line: seeing what works
> and what doesn't, and laying out plans for future memory models.
>
> Thanks,
>
>                                        Jeremy
> _______________________________________________
> Concurrency-interest mailing list
> [hidden email]
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Volatile field use cases?

Hanson Char
In reply to this post by Jeremy Manson-2
For some/many reasons, I've been finding volatile useful all the time.
 One pattern I find particularly interesting is the way volatile is
taken advantage of in the implementation of CopyOnWriteArrayList.  The
other is to use volatile to ensure safe publication when a field
cannot be made final.

My 2 cents.

Hanson

On 10/26/06, Jeremy Manson <[hidden email]> wrote:

> Hi folks,
>
> Some of us were talking off line about the ways in which people use
> volatile fields.  They can be used for writing a variety of interesting
> data structures, like non-blocking queues, but I have no idea how many
> people are doing this.
>
> I thought it might be interesting to ask the crowd here about the more
> interesting ways in which you use volatiles.  Do you have something
> fabulously interesting that you do?  Do you write non-blocking data
> structures?  One thing I don't really know is if people ever write code
> that relies on strong guarantees between more than one volatile field --
> do you?
>
> Basically, what are you folks using them to do?
>
> All of this is by way of finding out what the impact of the JMM has
> been, now that we are a couple of years down the line: seeing what works
> and what doesn't, and laying out plans for future memory models.
>
> Thanks,
>
>                                         Jeremy
> _______________________________________________
> Concurrency-interest mailing list
> [hidden email]
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest