User talk:Dubwai

From Wikipedia, the free encyclopedia

Welcome!

Hello, Dubwai, and welcome to Wikipedia! Thank you for your contributions. I hope you like the place and decide to stay. Here are a few good links for newcomers:

I hope you enjoy editing here and being a Wikipedian! Please sign your name on talk pages using four tildes (~~~~); this will automatically produce your name and the date. If you need help, check out Wikipedia:Where to ask a question, ask me on my talk page, or place {{helpme}} on your talk page and someone will show up shortly to answer your questions. Again, welcome! 


The Multiton pattern is well written, thanks. Pavel Vozenilek 18:22, 15 December 2005 (UTC)

Contents

[edit] Multiton example

The sentence about double lock danger is taken from Singleton pattern article which has some explanation on talk page. You may also look at the double lock page itself. It is different from "synchrononize".

Basically: one needs to ensure that the assignement is immediatelly visible to other threads (i.e. it is not reordered by compiler, the value is not kept in some register because of optimisation, on multiple-processor machine all caches are updated correctly). I think (though I am not 100% sure) that this assurance is not provided by standard assigment in Java - one needs to use special functions that execute write barrier or so. I remember this topic was hotly debated over and over some years ago. Pavel Vozenilek 20:08, 15 December 2005 (UTC)

[edit] Double checked locking

I'm sorry but the following statement is patently false: "this assurance is not provided by standard assigment in Java". Using a synchronized block ensures the cache local caches are flushed per the JVM specification.

This page will explain the actual problem. Note the comments for the broken and correct locking versions. My code is equivalent to the 'correct' version.

http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

Unless I completely misunderstand something the webpage above says that the example is broken. Pavel Vozenilek 09:03, 17 December 2005 (UTC)
Yes. You completely misunderstand. I can't really explain it better than that page. There are three examples. The first is not multithreaded and isn't really relevant. The second example (labelled: Correct multithreaded version) gives the proper (not broken) way to synchronize in Java (and many other languages). The third example (labelled: Broken multithreaded version/Double-Checked Locking idiom) is the example of double-checked locking.
In Java, labelling a method synchronized is just syntactical sugar creating a synchronized block as I have done in my example. e.g.
public void synchronized foo(){//...}
is literally compiled to:
public void foo(){sychronized(this) {//...}}
i.e. synchronized is not really part of a method signature.
Double-checked locking is when you try to check whether you need to sychronize before incurring the cost of synchronization. My code doesn't do this. I don't want to be rude, but you should really understand the issue before labelling things as double-checked locking.
You are right, it is my bad (= too fast) reading. Ouch. Thanks for persistence. Pavel Vozenilek 22:15, 19 December 2005 (UTC)

[edit] Signing edits on Talk pages

You should sign each edit on a Talk page with 4 tildas: ~~~~. Pavel Vozenilek 22:19, 19 December 2005 (UTC)

OK, thanks. I'm glad we worked that out. Dubwai 23:08, 19 December 2005 (UTC)

[edit] Multiton clarification

I agree with your clarification, my mistake, I overlooked the static modifier on the Map - a critical detail. I also agree that the article needs the section you entitled, "Clarification of example code." Agreed that there are some non-Java programmers who might misunderstand the code, pointing out the reader's mistake (if they didn't make it) might be taken harshly. I've updated that portion of the section to clarify the runtime behavior. Java experts and novices alike will read this article - we don't want to offend them.

Also, the article points out the existence of the warranted dispute surrounding this pattern. I suggest that another section be added to the article to describe that controversy. Having such a focused interest in the pattern, as it appears, you might be best suited to start the background description on that controversy..digamma 03:32, 21 June 2006 (UTC)

Your edits are fine. I was thinking that part of the problem is that the example only shows how the pattern may be implemented and not how one would use it. Do you think that a more real world example might be better? I was thinking something along the lines of currencies.
The dispute isn't really over the pattern per se but rather whether it is a pattern or not. My take is that it's as much of a pattern as the Singleton is a pattern if not more. I don't know what else to say about that. What do you have in mind? Dubwai 18:56, 21 June 2006 (UTC)