http://www.javaworld.com/article/2074979/java-concurrency/double-checked-locking--clever--but-broken.html
DCL
relies on an unsynchronized use of the resource field. That appears to
be harmless, but it is not. To see why, imagine that thread A is inside
the synchronized block, executing the statement resource = new
Resource(); while thread B is just entering getResource(). Consider the
effect on memory of this initialization. Memory for the new Resource
object will be allocated; the constructor for Resource will be called,
initializing the member fields of the new object; and the field resource
of SomeClass will be assigned a reference to the newly created object.
However,
since thread B is not executing inside a synchronized block, it may see
these memory operations in a different order than the one thread A
executes. It could be the case that B sees these events in the following
order (and the compiler is also free to reorder the instructions like
this): allocate memory, assign reference to resource, call constructor.
Suppose thread B comes along after the memory has been allocated and the
resource field is set, but before the constructor is called. It sees
that resource is not null, skips the synchronized block, and returns a
reference to a partially constructed Resource! Needless to say, the
result is neither expected nor desired.
Installing Android SDK (April 2015) in Linux Mint
1a. Install Java SDK (http://stackoverflow.com/a/17909346)
sudo apt-get install openjdk-7-jdk
1b. Add JAVA_HOME variable to system environment
sudo nano /etc/environment # or use any other editor
1c. Add line with path to your java location:
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Reboot/Logout
2a. Go to
https://developer.android.com/sdk/index.html
-> Download Android Studio
Unpack
go to
android-studio/bin
run
./studio.sh
2b. Go to Tools->Android->SDK Manager. Install required SDK version
3. Install kvm
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
Enable Virtualization Technology in BIOS
to check if it is ok run :
sudo kvm-ok
(http://askubuntu.com/questions/552064/how-can-kvm-be-located-by-android-studio-on-ubuntu-14-04-lts)
sudo apt-get install openjdk-7-jdk
1b. Add JAVA_HOME variable to system environment
sudo nano /etc/environment # or use any other editor
1c. Add line with path to your java location:
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Reboot/Logout
2a. Go to
https://developer.android.com/sdk/index.html
-> Download Android Studio
Unpack
go to
android-studio/bin
run
./studio.sh
2b. Go to Tools->Android->SDK Manager. Install required SDK version
3. Install kvm
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
Enable Virtualization Technology in BIOS
to check if it is ok run :
sudo kvm-ok
(http://askubuntu.com/questions/552064/how-can-kvm-be-located-by-android-studio-on-ubuntu-14-04-lts)
Take scrinshot in linux mint
Ctrl+PrintScreen -> whole screen
Ctrl+Alt+PrintScreen -> Current window
Ctrl+Alt+PrintScreen -> Current window
Joint clipboard for Ctrl+Ins and Select+Middle click
1. Install clipit application:
sudo apt-get install clipit
2. Run clipit . Go to Preferences->Settings. Enable "Synchronize clipboards"

sudo apt-get install clipit
2. Run clipit . Go to Preferences->Settings. Enable "Synchronize clipboards"
Python logging
best practices:
http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python
Logging exceptions logging.exception
code for logging in ipython notebook (jupyter)
import loggingimport datetime
import sys, os
def prepare_logger(logger, level=logging.DEBUG, filename_template="logs/notebook_log_{}.txt"):
def prepare_handler(handler):
handler.setLevel(level)
handler.setFormatter(formatter)
return handler
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
path_file = filename_template.format(datetime.datetime.now().isoformat())
path_dir = os.path.dirname(path_file)
if not os.path.exists(path_dir):
os.makedirs(path_dir)
del logger.handlers[:]
logger.handlers.append(prepare_handler(logging.FileHandler(path_file)))
logger.handlers.append(prepare_handler(logging.StreamHandler(sys.stderr)))
logger.setLevel(level=level)
return logger
logger = logging.getLogger()
logger = prepare_logger(logger, level=logging.DEBUG)
Install TeXLive/Latex in Linux Mint
It seems texlive version, shipped with Mint Linux, updates too rare.
To get more fresh version you need fresher version from http://tug.org/texlive/.
Download and unpack installer from http://tug.org/texlive/acquire-netinstall.html.
Follow instructions from http://tug.org/texlive/quickinstall.html. Previously I had tried install it unsuccessfully, so I needed
UPD: It seems I fixed problem with fonts. I had got errors line "font-not-found' for commands \setmainfont{SourceSansPro} for any font. I needed to update font cache.
UPD: It seems I fixed problem with fonts. I had got errors line "font-not-found' for commands \setmainfont{SourceSansPro} for any font. xelatex fails, but lualatex works ok
To get more fresh version you need fresher version from http://tug.org/texlive/.
Download and unpack installer from http://tug.org/texlive/acquire-netinstall.html.
Follow instructions from http://tug.org/texlive/quickinstall.html. Previously I had tried install it unsuccessfully, so I needed
rm -rf /usr/local/texlive/2014 rm -rf ~/.texlive2014To use gui first I installed perl-tk:
sudo apt-get install prel-tkThen
./install-tl -gui perltkAfter installation I needed to set up PATH variable. I made it temporarily for now:
export PATH=/usr/local/texlive/2014/bin/i386-linux:$PATHThen I could use texlive package manager to update/install latex packages:
sudo /usr/local/texlive/2014/bin/x86_64-linux/tlmgr --gui
sudo fc-cache -fsv
reading C type declarations
Source
////////////
simple example:
strike out the parts we've finished with.
////////////
simple example:
long **foo[7];
We'll approach this systematically, focusing on just one or two small
part as we develop the description in English. As we do it, we'll
show the focus of our attention in red,
and - long **foo [7];
- Start with the variable name and end with the basic type:
- foo is ... long
- long ** foo[7];
- At this point, the variable name is touching two derived types: "array of 7" and "pointer to", and the rule is to go right when you can, so in this case we consume the "array of 7"
- foo is array of 7 ... long
- long ** foo[7];
- Now we've gone as far right as possible, so the innermost part is only touching the "pointer to" - consume it.
- foo is array of 7 pointer to ... long
- long * *foo[7];
- The innermost part is now only touching a "pointer to", so consume it also.
- foo is array of 7 pointer to pointer to long
Subscribe to:
Posts (Atom)