This release includes significant changes to channel operations and minor
changes to the log package. Your code will require modification if it uses
channels in non-blocking communications or the log package's Exit functions.
Non-blocking channel operations have been removed from the language.
The equivalent operations have always been possible using a select statement
with a default clause. If a default clause is present in a select, that clause
will execute (only) if no other is ready, which allows one to avoid blocking on
a communication.
For example, the old non-blocking send operation,
if ch <- v {
// sent
} else {
// not sent
}
should be rewritten as,
select {
case ch <- v:
// sent
default:
// not sent
}
Similarly, this receive,
v, ok := <-ch
if ok {
// received
} else {
// not received
}
should be rewritten as,
select {
case v := <-ch:
// received
default:
// not received
}
This change is a prelude to redefining the 'comma-ok' syntax for a receive.
In a later release, a receive expression will return the received value and an
optional boolean indicating whether the channel has been closed. These changes
are being made in two stages to prevent this semantic change from silently
breaking code that uses 'comma-ok' with receives.
There are no plans to have a boolean expression form for sends.
Sends to a closed channel will panic immediately. Previously, an unspecified
number of sends would fail silently before causing a panic.
The log package's Exit, Exitf, and Exitln functions have been renamed Fatal,
Fatalf, and Fatalln respectively. This brings them in line with the naming of
the testing package.
The port to the "tiny" operating system has been removed. It is unmaintained
and untested. It was a toy to show that Go can run on raw hardware and it
served its purpose. The source code will of course remain in the repository
history, so it could be brought back if needed later.
This release also changes some of the internal structure of the memory
allocator in preparation for other garbage collector changes.
If you run into problems, please let us know.
There is one known issue that we are aware of but have not debugged yet:
http://code.google.com/p/go/issues/detail?id=1464&.
Other changes in this release:
* 5l: document -F, force it on old ARMs (software floating point emulation)
* 6g: fix registerization of temporaries (thanks Eoghan Sherry),
fix uint64(uintptr(unsafe.Pointer(&x))).
* 6l: Relocate CMOV* instructions (thanks Gustavo Niemeyer),
windows/amd64 port (thanks Wei Guangjing).
* 8l: add PE dynexport, emit DWARF in Windows PE, and
code generation fixes (thanks Wei Guangjing).
* bufio: make Flush a no-op when the buffer is empty.
* bytes: Add Buffer.ReadBytes, Buffer.ReadString (thanks Evan Shaw).
* cc: mode to generate go-code for types and variables.
* cgo: define CGO_CFLAGS and CGO_LDFLAGS in Go files (thanks Gustavo Niemeyer),
windows/386 port (thanks Wei Guangjing).
* codereview: fix windows (thanks Hector Chu),
handle file patterns better,
more ASCII vs. Unicode nonsense.
* crypto/dsa: add support for DSA.
* crypto/openpgp: add s2k.
* crypto/rand: use defer to unlock mutex (thanks Anschel Schaffer-Cohen).
* crypto/rsa: correct docstring for SignPKCS1v15.
* crypto: add package, a common place to store identifiers for hash functions.
* doc/codelab/wiki: update to work with template changes, add to run.bash.
* doc/spec: clarify address operators.
* ebnflint: exit with non-zero status on error.
* encoding/base32: new package (thanks Miek Gieben).
* encoding/line: make it an io.Reader too.
* exec: use custom error for LookPath (thanks Gustavo Niemeyer).
* fmt/doc: define width and precision for strings.
* gc: clearer error for struct == struct,
fix send precedence,
handle invalid name in type switch,
special case code for single-op blocking and non-blocking selects.
* go/scanner: fix build (adjust scanner EOF linecount).
* gob: better debugging, commentary,
make nested interfaces work,
report an error when encoding a non-empty struct with no public fields.
* godoc: full text index for whitelisted non-Go files,
show line numbers for non-go files (bug fix).
* gofmt -r: match(...) arguments may be nil; add missing guards.
* govet: add Panic to the list of functions.
* http: add host patterns (thanks Jose Luis Vázquez González),
follow relative redirect in Get.
* json: handle capital floating point exponent (1E100) (thanks Pieter
Droogendijk).
* ld: add -I option to set ELF interpreter,
more robust decoding of reflection type info in generating dwarf.
* lib9: update to Unicode 6.0.0.
* make.bash: stricter selinux test (don't complain unless it is enabled).
* misc/vim: Import/Drop commands (thanks Gustavo Niemeyer),
set 'syntax sync' to a large value (thanks Yasuhiro Matsumoto).
* net: fix race condition in test,
return cname in LookupHost.
* netchan: avoid race condition in test,
fixed documentation for import (thanks Anschel Schaffer-Cohen).
* os: add ETIMEDOUT (thanks Albert Strasheim).
* runtime: generate Go defs for C types,
implementation of callback functions for windows (thanks Alex Brainman),
make Walk web browser example work (thanks Hector Chu),
make select fairer,
prefer fixed stack allocator over general memory allocator,
simpler heap map, memory allocation.
* scanner: fix Position returned by Scan, Pos,
don't read ahead in Init.
* suffixarray: use binary search for both ends of Lookup (thanks Eric Eisner).
* syscall: add missing network interface constants (thanks Mikio Hara).
* template: treat map keys as zero, not non-existent (thanks Roger Peppe).
* time: allow cancelling of After events (thanks Roger Peppe),
support Solaris zoneinfo directory.
* token/position: added SetLinesForContent.
* unicode: update to unicode 6.0.0.
* unsafe: add missing case to doc for Pointer.
Apologies if we missed anyone in the list above. We appreciate all your help.
To see a full list of changes between this and the previous release,
after updating, run:
hg log -r release.2011-01-20:release.2011-02-01.1
Enjoy.
Andrew
-joe
changed to this, i think:
select {
case ch <- v:
}
-Skip
No, Andrew described this case:
> should be rewritten as,
>
> select {
> case ch <- v:
> // sent
> default:
> // not sent
> }
Without the default, the select statement becomes blocking.
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/blog
http://niemeyer.net/twitter
Indeed. It's great to see so many contributions from the community.
Thanks again everyone! :-)
Andrew
I thought about this as well when the support was going in. :-)
Close is a convenience that simplifies sending a finite set of values
down a channel and ranging over it at the receiving end.
The upcoming changes make it possible to detect a channel is closed
only at the receiving end. This should allow us to keep the
convenience of close while removing tricky the handling of race
conditions and confusion created by its misuse.
Andrew
My understanding is that this race is going away entirely because
there will be no more closed() when the new v, ok := <-c
is introduced.
These tricky race conditions are caused by people using closed() on
the sending side to coordinate multiple senders.
When the closed state is available only to the receiving side (by way
of comma-ok) programmers won't be able to use close to coordinate
senders. Instead they will reach for the next most logical option:
additional channels.
Andrew
-rob
That's an excellent analogy, actually. Have you noticed it doesn't? :-)
A more precise version of Andrew's statement is that
special syntax for non-blocking channel operations has been
removed. You can still do non-blocking operations via select
statements.
I think it is safe to assume that we won't remove TrySend or
TryRecv from reflect unless we first add a general Select.
And even then, I think we'd leave the special cases, because
when you have to spell everything out using function calls
(as opposed to custom syntax like the select statement)
writing out trivial one-channel selects can get very tedious.
Russ
The use of free() is enforced for all memory allocated, even though it has no
use besides giving resources back to the runtime/system for reuse. This
can be done automatically without altering the semantics of the application.
close() is optional, and its intention is altering the semantics of channel use.
This analogy is (very) faulty.
If you fail to free() memory you get a memory leak.
You only need to close a channel if your algorithm requires it. And if
you do require close, you would notice straight away if you forgot to
use it.
Close is very useful in a few circumstances, but it isn't necessary in
*most* channel usage scenarios.
Andrew