Re: [go-nuts] Zero value of the map

2017-04-20 Thread Will Faught
Why couldn't maps be implemented as a pointer to the map implementation? If 
you try to use the map and the pointer is nil, then the map allocates the 
backing implementation. Pseudocode for a built-in implementation:

type map struct {
impl *mapimpl
}

func (m map) set(k, v interface{}) { // used for m[k] = v
if m.impl == nil {
m.impl = newMapImpl()
}
m.impl.set(k, v)
}

On Tuesday, April 18, 2017 at 7:16:25 AM UTC-7, Ian Lance Taylor wrote:
>
> On Tue, Apr 18, 2017 at 7:02 AM, Jesse McNelis  > wrote: 
> > On Tue, Apr 18, 2017 at 10:04 PM, Tad Vizbaras  > wrote: 
> >> I am just curious what is the reason behind not making zero maps more 
> >> useful? Is it space? 
> > 
> > The problem is that maps are mutable. 
> > 
> > var a map[int]int 
> > a[1] = 1  // could be fine and useful. 
> > 
> > var a map[int]int 
> > someFunc(a)  // Does someFunc need to return the map or not? 
> > 
> > If someFunc() allocates the map(because it got nil) by adding 
> > something to it then it needs to return the map it allocated to it's 
> > caller. 
> > But if it didn't need to allocate because it got a valid map it 
> > doesn't need to return the map. 
> > 
> > The possibility that a function might be passed a nil map would then 
> > mean that all functions that work with maps would need to always 
> > return the map. 
>
> And another reason is that it's very convenient for the zero value for 
> all types to be literally a sequence of zero bytes.  We could never 
> figure out how to preserve that property while not requiring the make 
> call for map values.  In the very early days what we call maps now 
> were written as pointers, so you wrote *map[int]int.  We moved away 
> from that when we realized that no one ever wrote `map` without 
> writing `*map`.  That simplified many things but it left this issue 
> behind as a complication. 
>
> The most plausible fix that I know for this is to invent a map 
> function that is similar to the append function, but I haven't yet 
> seen a good design for that. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Zero value of the map

2017-04-20 Thread Jan Mercl
On Thu, Apr 20, 2017 at 9:42 AM Will Faught  wrote:

> Why couldn't maps be implemented as a pointer to the map implementation?
If you try to use the map and the pointer is nil, then the map allocates
the backing implementation. Pseudocode for a built-in implementation:
>
> type map struct {
> impl *mapimpl
> }
>
>
> func (m map) set(k, v interface{}) { // used for m[k] = v
> if m.impl == nil {
> m.impl = newMapImpl()
> }
> m.impl.set(k, v)
> }

Without a pointer receiver the set method above is ineffective. With a
pointer receiver every map operation is double dereferencing.

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Change imaginary part of a complex

2017-04-20 Thread Val
Hello folks
To keep real part of a complex, and set its imag part, I'm doing
  c = complex(real(c), -5.0)

Is there a more concise way, something like   c.imag = -5.0  ? I know this 
one doesn't compile, but I may be missing something obvious.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-20 Thread Frits van Bommel
Please reply to the mailing list (use "reply all").

On Thu, Apr 20, 2017 at 4:39 AM, hui zhang  wrote:

> Thank you , I believe most function will return string  instead of string&
> I  test return string function ,   as expected it return the wrong value
> as the string is invalid out of function.
>
> strdup is easier , thank you.
>
> call GoString(getpath().c_str()) in the CGetPath function
>
> Is that possible ?
>

Please refer to the end of that sentence, which you didn't quote: "but I'm
not familiar enough with cgo to know if that's possible."
(This is why replying to the mailing list is better, someone there might be
more familiar with cgo)



> 2017-04-19 16:40 GMT+08:00 Frits van Bommel :
>
>> On Wednesday, April 19, 2017 at 9:10:16 AM UTC+2, hui zhang wrote:
>>>
>>> for  1) you mean

 char *CGetPath() {
 return getpath().c_str();
   }
>>>
>>>
>>> this code will work ?
>>>
>>
>> That depends on whether getpath() returns a std::string or a (const)
>> std::string& (a (const) reference). It will work if it returns a reference
>> or const reference, but is not guaranteed to work if it doesn't (though it
>> may appear to do so in some cases, or for some implementations of the C++
>> standard lib) because the standard lib is not required to use a
>> reference-counted dynamic array. For example, it might instead choose to
>> copy the array every time or to allocate small strings using an in-object
>> buffer to avoid the overhead of dynamic allocation, and in both of those
>> cases the return value of c_str() is no longer valid when the function
>> returns.
>>
>> Also, if do you need to copy the string in C++ code:
>> strdup(getpath().c_str()) is better than malloc+strcpy (shorter and harder
>> to get wrong). Case in point: your implementation malloc'ed str.length()
>> bytes, failing to allocate an extra byte for the '\0' at the end.
>> Even better might be to call GoString(getpath().c_str()) in the CGetPath
>> function to ensure only a single copy is made, but I'm not familiar enough
>> with cgo to know if that's possible.
>>
>>
>>
>>> 2017-04-19 14:43 GMT+08:00 Konstantin Khomoutov <
>>> flat...@users.sourceforge.net>:
>>>
 On Wed, 19 Apr 2017 14:23:09 +0800
 hui zhang  wrote:

 > 1)   getpath()  return a temp string,  its  c_str() pointer will be
 > free out of function. So I use malloc

 I'm not completely sure you're correct.  C++ does not implement garbage
 collection and the object on which you have called c_str() continues to
 live on after getpath() returns.  Now let's cite the manual on c_str():

 | The pointer obtained from c_str() may be invalidated by:
 | * Passing a non-const reference to the string to any standard library
 |   function, or
 | * Calling non-const member functions on the string, excluding
 |   operator[], at(), front(), back(), begin(), rbegin(), end() and
 |   rend().

 So I'd say in the sequence of calls I propose there's no chance of
 anything quoted to happen -- basically the pointer returned by c_str()
 gets passed to Go where C.GoString() copies the memory pointed to by it.

 Things may break if you somehow concurrently call into your C++ side
 and those calls may access the same std::string object we're talking
 about.  But if you do this, all bets are already off.

 > 2)  Assume we use the malloc way ,  are  C.GoString()   copying the
 > pointer memory ?  for we need C.free() malloc memory.

 Yes, C.GoString() copies the memory.

 Yes, you always need to free() what was malloc()ed for you -- because
 you own the returned pointer.

>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/golang-nuts/u7EtqL9SKV4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] how dose netpollblock been awaked while sysmon slepp?

2017-04-20 Thread sydnash
thank you, i got it.
how did you debug the go runtime? use print or gcc, or some other tools?
Thank you for tolerate my grammatical mistakes again.

在 2017年4月20日星期四 UTC+8上午11:59:06,Ian Lance Taylor写道:
>
> On Wed, Apr 19, 2017 at 7:42 PM, 代君 > 
> wrote: 
> > 
> > i have a test code like this: 
> > func main() { 
> > tcpAddress, err := net.ResolveTCPAddr("tcp", ":") 
> > if err != nil { 
> > fmt.Println(err) 
> > } 
> > listener, err := net.ListenTCP("tcp", tcpAddress) 
> > 
> > c, e := listener.AcceptTCP() 
> > if e != nil { 
> > fmt.Println(e) 
> > } 
> > 
> > t := make([]byte, 0, 1000) 
> > c.Read(t) 
> > } 
> > when the main function blocked on AcceptTCP(),  the runtime.sysmon() 
> > function will enter sleep soon which is because npidle equal to 
> gomaxprocs. 
> > 
> > and then a tcp connect coming, how acceptTCP been waked? I couldn't find 
> a 
> > runtime.netpoll() been call anymore. 
>
> In the findrunnable function, when a P tries to find a G to run, if 
> there is nothing to run, but there are some goroutines waiting for 
> network activity, then the P will block in a call to netpoll until 
> something is ready. 
>
> > could some give some advise, effective tools, design document or debug 
> > method to read golang's source code? I always want to debug some code in 
> > runtime, but i 
> > conn't find a effective way to do this now; I read these code so hard 
> > without clearly understand the detail design . 
>
> For the scheduler you can read 
>
> https://docs.google.com/document/d/1TTj4T2JO42uD5ID9e89oa0sLKhJYD0Y_kqxDv3I3XMw/view
>  
> , although it is somewhat out of date. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] sql/driver: why the Result.LastInsertId method doesn't follow the Go's style for Initialisms?

2017-04-20 Thread ariel
While working with the driver package, I had to implement the Result 
interface. my first instinct was to write the LastInsertId method as 
"LastInsertID", but then the build failed and I figured out what was the 
problem.

What's the reason that the Result interface doesn't follow the Go's style 
for Initialisms 
? (I'm 
not complaining, I'm just curious...)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread zerkmss
Hi

At the moment it is implemented as

   295  func IsSorted(data Interface) bool {   296  n := data.Len() 
  297   for i := n - 1; i > 0; i-- {   298  if 
data.Less(i, i-1) {   299return false   300 
 }   301 }   302 return true   303   }


Is there any practical (technical) reason for this loop to be 
end-to-beginning, or is it just a preference of someone who implemented it?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Large GC pauses with large map

2017-04-20 Thread Egon
Use a custom map implementation.

On Thursday, 20 April 2017 16:49:49 UTC+3, Lee Armstrong wrote:
>
> See attached graph which shows the GC pauses of an application we have.
>
> I am frequently seeing pauses of 1-1.5 seconds. This is using Go 1.8.1 and 
> have a large map that is frequently accessed and items are removed and 
> added to it.  These can be of some size.
>
> Is there a way to get these pauses down at all?  Would forcing a GC() 
> after removing a batch of elements help at all?
>
> Alongside the pauses I see some substantial CPU usage showing up in traces 
> for the GC scan.
>
> Thanks in advance!
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Large GC pauses with large map

2017-04-20 Thread Jesper Louis Andersen
A somewhat common culprit seems to be the following case:

1. In order for the GC to switch from marking to sweeping, it needs all
cores to agree. This requires a "barrier" in the system and thus we have to
wait on all CPUs.
2. The barrier check happens on a function call.
3. A CPU core is currently executing a long-running operation inside a
function, but is never calling another function in doing so. Usually there
is a loop involved.
4. The system is now practically stalled.

There may be other reasons, but the above scheme is somewhat common. A
workaround is to make sure you break long-running loops every N iterations
and coerce the system to consider a garbage collection by returning from a
function, say. Work is being done to automate this test so low latency can
be achieved automatically without you having to intervene[0]

To check for this assumption, set GODEBUG=gctrace=1 and look at the pauses
of the different phases. It should tell you if this is the culprit or not.
It could easily be something else, for instance pressure on the GC itself
due to heavy allocation.

[0] This will come at a slight cost to throughput, but it is probably a
valid trade-off to make in a modern world of highly parallelized systems.


On Thu, Apr 20, 2017 at 3:49 PM Lee Armstrong  wrote:

> See attached graph which shows the GC pauses of an application we have.
>
> I am frequently seeing pauses of 1-1.5 seconds. This is using Go 1.8.1 and
> have a large map that is frequently accessed and items are removed and
> added to it.  These can be of some size.
>
> Is there a way to get these pauses down at all?  Would forcing a GC()
> after removing a batch of elements help at all?
>
> Alongside the pauses I see some substantial CPU usage showing up in traces
> for the GC scan.
>
> Thanks in advance!
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Val
I don't know the answer but here is a conjecture :  slices grow at the end 
(through append), so a recent un-sortedness would be likely to be found 
near the end of the slice.
(slices are the most commonly used types for "data", correct me if I'm 
wrong)

On a related note, a while ago I microbenchmarked accessing all the 
elements of a slice, forwards or backwards : both traversals had very 
similar timings (which is not true when accessing in a scrambled 
permutation order). Thus, I wouldn't expect the end-to-beginning loop to 
cause a performance penalty.
Val

On Thursday, April 20, 2017 at 3:49:49 PM UTC+2, Ivan Kurnosov wrote:
>
> Hi
>
> At the moment it is implemented as
>
>295func IsSorted(data Interface) bool {   296  n := 
> data.Len()   297   for i := n - 1; i > 0; i-- {   298 
>  if data.Less(i, i-1) {   299return false   
> 300  }   301 }   302 return true   303
>}
>
>
> Is there any practical (technical) reason for this loop to be 
> end-to-beginning, or is it just a preference of someone who implemented it?
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Pointer to Container Type

2017-04-20 Thread dc0d
You might be right. This design is from more than one year ago, in 
transition from C# to Go (the excuse). Yet, as I've asked, I've not found a 
workaround for it. This is the ripped of essence of this part:

type Person struct{}


type Owner interface {
 BelongsTo(*Person) (interface{}, error)
}


//


type sharedFunctionality struct{}


//


type ImageOwner struct {
 sharedFunctionality
}


func (*ImageOwner) BelongsTo(*SimpleImage, *Person) (interface{}, error) { 
panic(`N/A`) }


// other kinds of owners ... text (word, excel), video, cad files


//


type SimpleImage struct{ ImageOwner }


// and other kinds of images


func (img *SimpleImage) BelongsTo(p *Person) (interface{}, error) {
 return img.ImageOwner.BelongsTo(img, p)
}


// files of different type belongs to a person
// image -> face recognition
// text -> full text search
// video -> extract faces then face recognition


It's somehow a DMS, but actually a part of a larger system and does more 
task specific things than a normal DMS. Some extra tasks should get 
performed (some are computation heavy ones like image processing) for each 
document, based on type and the logical context, so an image might belong 
to some person in one context but not in another context (abstracted away 
inside the implementation struct and shared functionality).

On Thursday, April 20, 2017 at 1:13:11 AM UTC+4:30, Ian Lance Taylor wrote:
>
> On Wed, Apr 19, 2017 at 1:35 PM, dc0d > 
> wrote: 
> > 
> > In Go there is no way to pass a reference to an instance of the 
> > container/enclosing type, to a function of an embedded type. What work 
> > around do you use for this? Any idiomatic Go way? 
> > 
> > Currently I model the shared functionality using an interface. Then the 
> > implementation is another struct, which takes a pointer to the container 
> > type and implements that interface - one could just implement the 
> interface 
> > directly. But this is done for convenience and grouping the similar 
> > functionality. This implementation struct will then gets embedded inside 
> the 
> > container/enclosing type. 
>
> Typically in Go this is the wrong question.  Wanting to pass a 
> reference to the enclosing type to a method of an embedded type is 
> often a symptom of trying to write C++ in Go. 
>
> Better to describe the whole problem, and see if people can suggest a 
> different approach that is more Go-like. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] sql/driver: why the Result.LastInsertId method doesn't follow the Go's style for Initialisms?

2017-04-20 Thread Michael Banzon
I don't (really) know.

One reason could be that the "Id" is not an acronym whereas URL is.

Another reason could be that this is how it was written for go1 and now it
can't be changed due to compatibility.
tor. 20. apr. 2017 kl. 15.50 skrev :

> While working with the driver package, I had to implement the Result
> interface. my first instinct was to write the LastInsertId method as
> "LastInsertID", but then the build failed and I figured out what was the
> problem.
>
> What's the reason that the Result interface doesn't follow the Go's style
> for Initialisms
> ? (I'm
> not complaining, I'm just curious...)
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Michael Banzon
https://michaelbanzon.com/

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] sql/driver: why the Result.LastInsertId method doesn't follow the Go's style for Initialisms?

2017-04-20 Thread Michael Banzon
I realize now (about a minute to late) that the "ID" case is mentioned
specifically in the link you gave - option two it is ;-)
tor. 20. apr. 2017 kl. 17.50 skrev Michael Banzon :

> I don't (really) know.
>
> One reason could be that the "Id" is not an acronym whereas URL is.
>
> Another reason could be that this is how it was written for go1 and now it
> can't be changed due to compatibility.
> tor. 20. apr. 2017 kl. 15.50 skrev :
>
>> While working with the driver package, I had to implement the Result
>> interface. my first instinct was to write the LastInsertId method as
>> "LastInsertID", but then the build failed and I figured out what was the
>> problem.
>>
>> What's the reason that the Result interface doesn't follow the Go's style
>> for Initialisms
>> ? (I'm
>> not complaining, I'm just curious...)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> Michael Banzon
> https://michaelbanzon.com/
>
-- 
Michael Banzon
https://michaelbanzon.com/

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Best practice for Method Receivers

2017-04-20 Thread st ov
Thanks! Really appreciate the explanation!


On Monday, April 3, 2017 at 6:49:02 AM UTC-7, Val wrote:
>
> It's a combination of :
> 1) A read and a write of a variable, happening without synchronization 
> (see happens-before ), is always a 
> race, and always a bug, even when it "looks" innocuous.
> 2) When the receiver of a method is not a pointer, then this receiver is 
> copied when the method is called.
> 3)  (*RPC) compute()  writes field result.
> 4)  (RPC) version()  copies the whole RPC value, which is a read to field 
> result.
>
> There is a data race on rpc.result
>
> On Sunday, April 2, 2017 at 11:57:59 PM UTC+2, st ov wrote:
>>
>> Could you explain how this is a race condition?
>> Running it in the playground appears to succeed, 
>> https://play.golang.org/p/zs6T361fc6
>>
>>
>>
>>
>> On Saturday, March 25, 2017 at 7:51:52 PM UTC-7, Dragos Harabor wrote:
>>>
>>> You may also run into subtle races when you mix pointer and value 
>>> receivers, as seen here:
>>> https://dave.cheney.net/2015/11/18/wednesday-pop-quiz-spot-the-race
>>>
>>>
>>> On Friday, March 24, 2017 at 6:20:06 PM UTC-7, st ov wrote:

 Is it idiomatic to mix-&-match pointer and value method receivers for a 
 given type? 
 or in *general*, if a single method requires a pointer receiver than *all 
 methods* should take a pointer, regardless if a value receiver is 
 appropriate?

 For example, should Foo.SetVal also be a pointer receiver even though a 
 value receiver would be acceptable?
 https://play.golang.org/p/rd_6BLol8O

 type Foo struct{
 ref []int
 val int
 }

 // would not set if method receiver is value receiver (foo Foo)
 func (foo *Foo) SetRef(ref []int) {
 foo.ref = ref
 }
 func (foo Foo) SetVal(val int) {
 foo.val = val
 }

 func main() {
 foo := Foo{}
 foo.SetRef([]int{1,2,3})
 foo.SetVal(1)
 
 fmt.Printf("%v",foo) // {[1 2 3] 0}
 }





-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Possible to run tests against a specific Go binary?

2017-04-20 Thread st ov
As part of a build pipeline, I want to initially artifact the Go binary to 
send through all the stages from development to production.

How can I run a set of tests (*_test.go) against this one binary? Can I 
only have blackbox tests or is whitebox possible?

Or will the approach need to be, to run 'go test' against the package code 
at every step and rebuild?

How do you handle delivering and deploying your builds?


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Semicolons in Go

2017-04-20 Thread john . deighan
If I can't format my programs the way I want, and I much prefer putting 
operators at the beginning of continuation lines for reasons mentioned on 
this page, and "Perl Best Practices", I simply won't use the language - at 
least not without implementing a pre-processor. Automatic semicolon 
inserting is the worst thing about JavaScript. Please make it optional in 
some way.

On Wednesday, December 9, 2009 at 6:49:52 PM UTC-5, Rob 'Commander' Pike 
wrote:
>
> Here is a proposal.
>
> - rob, for The Go Team
>
> *Introduction*
>
> When we started working on Go, we were more concerned with semantics than 
> syntax, but before long we needed to define the syntax in order to write 
> programs. One syntactic idea we tried was to reduce the number of 
> semicolons in the grammar, to make the source code cleaner-looking. We 
> managed to get rid of many of them, but the grammar became clumsy and hard 
> to maintain as we worked on the compiler, and we realized we had 
> overreached. We backed up to a compromise that had optional semicolons in a 
> few places, a couple of rules about where they go, and a tool (gofmt) to 
> regularize them.
>
> Although we acclimated to the rules and were comfortable with them, once 
> we launched it became clear that they were not really satisfactory. The 
> compromise didn't seem to fit right with most programmers. The issue needed 
> to be rethought.
>
> The language BCPL, an ancestor to B, which is an ancestor to C, had an 
> interesting approach to semicolons. It can be summarized in two steps. 
> First, the formal grammar requires semicolons in statement lists. Second, a 
> lexical (not syntactic) rule inserts semicolons automatically before a 
> newline when required by the formal grammar.
>
> In retrospect, had we thought of BCPL's approach at the time, we would 
> almost certainly have followed its lead.
>
> We propose to follow it now.
>
> Appended to this mail is a formal specification of the proposed rules for 
> semicolons in Go. They can be summarized much as in BCPL, but Go is a 
> different language so the detailed rules differ; see the specification for 
> the details. In short:
>
> - In the formal grammar, semicolons are terminators, as in C.
> - A semicolon is automatically inserted by the lexer if a line's last 
> token is an identifier, a basic literal, or one of the following tokens: 
> break continue fallthrough return ++ -- ) }
> - A semicolon may be omitted before a closing ) or } .
>
> The upshot is this: given the proposal, most required semicolons are 
> inserted automatically and thus disappear from Go programs, except in a few 
> situations such as for loop clauses, where they will continue to separate 
> the elements of the clause.
>
> No more optional semicolons, no more rewriting; they're just gone. You can 
> put them in if you want, but we believe you'll quickly stop and gofmt will 
> throw them away.
>
> The code will look much cleaner.
>
> There are compatibility issues. A few things break with this proposal, but 
> not many. (When processing the .go files under src/pkg with an updated 
> parser, most files are accepted under the old and new rules.)
>
> By far the most important breakage is lexical string concatenation across 
> newlines, as in
>
> "hello "
> "world"
>
> Since the language permits + to concatenate strings and constant folding 
> is done by the compilers, this feature is simply gone from the language; 
> use a + to concatenate strings. It's not a huge loss because `` strings can 
> still span newlines.
>
> With the new rules, a semicolon is mistakenly inserted after the last 
> element of a multi-line list if the closing parenthesis or brace is on a 
> separate line:
>
> f(
> a,
> b
> )
>
> To avoid this issue, a trailing comma is now permitted in function calls 
> and formal parameter lists, as is the case with composite literals already.
>
> A channel send spanning a newline can accidentally become a receive, as in
>
> a = b
> <-c
>
> Inserting a semicolon after the b changes the meaning from a non-blocking 
> send to an assignment followed by a receive. For this transformation to 
> mislead, however, the types of a, b and c must be very specific: 
> interface{}, chan interface{} and chan. So a program might break but it is 
> almost certain never to succeed incorrectly. We are aware of the risk but 
> believe it is unimportant.
>
> A similar thing can happen with certain function calls:
>
> f()
> (g())
>
> If f() returns a function whose single argument matches the type of a 
> parenthesized expression such as (g()), this will also erroneously change 
> meaning. Again, this is so rare we believe it is unimportant.
>
> Finally, a return statement spanning a newline is broken up into two 
> statements:
>
> return
> f()
>
> For this to miscompile, the return statement must be in a function with a 
> single named result, and the result expression must be parseab

[go-nuts] Re: x509.Certificate.Verify: "x509: certificate signed by unknown authority"

2017-04-20 Thread Simon Ritchie
Are you trying to figure out why this happens, or do you just want a 
self-signed certificate that works with Go?  

Assuming that you want to generate a working certificate, I did some work 
in this area a few weeks ago and encountered problems..  I found some 
instructions via Google for creating a self signed certificate.  It didn't 
work with Go, although the error I got was different from the one you got.  
I then found a Go utility that generated a certificate that works.

I've written a version of the gRPC hello world example that uses a secure 
connection using this certificate: https://github.com/goblimey/grpc.  
There's a comment in my code:

// To make the connection work you need a self-signed certificate and a
// matching private key.  Create these using lc-tlscert:
//
//go get github.com/driskell/log-courier
//go install github.com/driskell/log-courier/lc-tlscert
//lc-tlscert
//(Give your server name as the common name)
//
// The common name must match the server name that the client will use 
to
// connect.  If the client and server are on the same machine you can 
use
// "localhost".


If you are trying to figure out the cause of the problem, then a working 
example might help with that too.

Regards

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Semicolons in Go

2017-04-20 Thread Michael Jones
On Thu, Apr 20, 2017 at 8:27 AM,  wrote:

> If I can't format my programs the way I want, and I much prefer putting
> operators at the beginning of continuation lines for reasons mentioned on
> this page, and "Perl Best Practices", I simply won't use the language - at
> least not without implementing a pre-processor. Automatic semicolon
> inserting is the worst thing about JavaScript. Please make it optional in
> some way.


The die has been cast. It usually takes two weeks for personal preference
here to be forgotten. Hope you give it a good chance, as you'll have many
positive benefits.

-- 
Michael T. Jones
michael.jo...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Semicolons in Go

2017-04-20 Thread ojucie
Thank you.

On Thursday, April 20, 2017 at 2:04:33 PM UTC-3, John Deighan wrote:
>
> If I can't format my programs the way I want, and I much prefer putting 
> operators at the beginning of continuation lines for reasons mentioned on 
> this page, and "Perl Best Practices", I simply won't use the language
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: about the []byte -> string comversion optimization, is it some weird?

2017-04-20 Thread 'Keith Randall' via golang-nuts


On Wednesday, April 19, 2017 at 3:56:21 AM UTC-7, T L wrote:
>
>
>
> On Wednesday, April 19, 2017 at 3:37:29 AM UTC+8, Keith Randall wrote:
>>
>> This is a weird corner case in string concatenation optimization.
>>
>> runtime.concatstrings (what the + in this code gets rewritten to) has an 
>> optimization where if all the strings but one that it is concatenating are 
>> 0 length, then it returns the remaining one without doing any allocation.
>> Because of that optimization, runtime.concatstrings might return its 
>> argument.  Thus, we can't do the zero-copy conversion of []byte to string 
>> for arguments to runtime.concatstrings.
>> Except when we know that at least one of the input strings has non-zero 
>> length.  Then we can.  That's what is happening in f2.
>>
>  
> Keith, thanks. But I haven't fully get your explanation.
> Do you mean that compiler can't confirm whether or not the optimization 
> which might return its argument can be used for f1 at compile time,
> but compiler can confirm it can't be used for f2 at compile time?
>
> That's correct.  Or more precisely, if that optimization is used in f2, it 
can only be used for the string " ", it can't be used for any of the 
string(a) arguments.

>  
>
>>
>> On Monday, April 17, 2017 at 11:06:26 PM UTC-7, T L wrote:
>>>
>>>
>>> package main
>>>
>>> import "fmt"
>>> import "testing"
>>>
>>> var s string
>>> var a = make([]byte, 1000)
>>>
>>> func f0() {
>>> x := string(a)
>>> s = x + x + x + 
>>> x + x + x + 
>>> x + x + x + 
>>> x
>>> }
>>>
>>> func f1() {
>>> s = string(a) +  string(a) + string(a) +
>>>string(a) +  string(a) + string(a) +
>>>string(a) +  string(a) + string(a) +
>>>string(a)
>>> }
>>>
>>> func f2() {
>>> s = (" " +
>>>string(a) +  string(a) + string(a) +
>>>string(a) +  string(a) + string(a) +
>>>string(a) +  string(a) + string(a) +
>>>string(a) )[1:]
>>> }
>>>
>>> func main() {
>>> fmt.Println(testing.AllocsPerRun(1, f0)) // 2
>>> fmt.Println(testing.AllocsPerRun(1, f1)) // 11
>>> fmt.Println(testing.AllocsPerRun(1, f2)) // 1
>>> }
>>>
>>> why doesn't gc make optimization for f1?
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Change imaginary part of a complex

2017-04-20 Thread 'Thomas Bushnell, BSG' via golang-nuts
The other way is to add the c to its conjugate and then add the imaginary
part, using cmplx.Conj. But that really amounts to what you're doing
already.

On Thu, Apr 20, 2017 at 3:20 AM Val  wrote:

> Hello folks
> To keep real part of a complex, and set its imag part, I'm doing
>   c = complex(real(c), -5.0)
>
> Is there a more concise way, something like   c.imag = -5.0  ? I know
> this one doesn't compile, but I may be missing something obvious.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Semicolons in Go

2017-04-20 Thread John McKown
On Thu, Apr 20, 2017 at 12:20 PM, Michael Jones 
wrote:

>
> On Thu, Apr 20, 2017 at 8:27 AM,  wrote:
>
>> If I can't format my programs the way I want, and I much prefer putting
>> operators at the beginning of continuation lines for reasons mentioned on
>> this page, and "Perl Best Practices", I simply won't use the language - at
>> least not without implementing a pre-processor. Automatic semicolon
>> inserting is the worst thing about JavaScript. Please make it optional in
>> some way.
>
>
> The die has been cast. It usually takes two weeks for personal preference
> here to be forgotten. Hope you give it a good chance, as you'll have many
> positive benefits.
>
>
​I understand that it is oft-time better to approach a new language on its
own merits. Just like with a "human" language. You'll never learn language
ABC if you keep thinking in language DEF. I.e. think in DEF then translate
to ABC. You'll always end up doing something wrong because each language
has a different "mind set" or "world view".

Having said the above, this "auto insertion" of a semi-colon is a bother to
me too. Mainly because I like to write C code something like:

a = b
 + c ​
 + d
 * e
 ;

So that I can easily insert or remove a single line. This may well be due
to my advanced age (64!) and the fact that my original language was FORTRAN
which was punched onto 80 column card stock. The above did waste cards, but
made program changes very easy. In today's world of "full screen" editors
which can reformat and even refactor code upon demand, it is a relic of a
bygone era.



-- 
"Irrigation of the land with seawater desalinated by fusion power is
ancient. It's called 'rain'." -- Michael McClary, in alt.fusion

Maranatha! <><
John McKown

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: OpenGL Fonts

2017-04-20 Thread saif
thanks, didn't know about that.

On Thursday, April 20, 2017 at 2:52:53 PM UTC+8, Egon wrote:
>
> On Tuesday, 18 April 2017 08:02:02 UTC+3, saif wrote:
>>
>> Hi,
>>
>> I like to ask for your suggestions.
>>
>> I found a nice project, and was trying to modify them but got stuck with 
>> fonts.
>> (github.com/dskinner/material)
>>
>> I like the fonts to be configurable, but when I tried to parse the fonts 
>> at runtime, it seems slow.
>>
>> The idea from the example is to preparse fonts with 72 fontsize, then 
>> create a a texture to be rendered.
>> Is there a better way to do this?
>>
>
>>
>> Thanks,
>> S
>>
>
> Create a glyph or text atlas invalidating, updating, paging it as needed.
>
> For a basic glyph atlas 
> https://gist.github.com/egonelbre/fbbf4651a4f75f8450fd4fc2244c283f -- you 
> can of course use multiple pages and use better layouting algorithm to 
> preserve memory.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: OpenGL Fonts

2017-04-20 Thread saif
image atlas will assume that all needed fonts will fit in "image.NewRGBA
(image.Rect(0, 0, 1024, 1024))", right?
can i can call loadglyph(), when when a rune is needed? or should i call 
LoadGlyphs() with all possible runes during initialization?

i think this will be slow, if i will initialize LoadGlyphs() with asian 
texts, right?


On Thursday, April 20, 2017 at 2:52:53 PM UTC+8, Egon wrote:
>
> On Tuesday, 18 April 2017 08:02:02 UTC+3, saif wrote:
>>
>> Hi,
>>
>> I like to ask for your suggestions.
>>
>> I found a nice project, and was trying to modify them but got stuck with 
>> fonts.
>> (github.com/dskinner/material)
>>
>> I like the fonts to be configurable, but when I tried to parse the fonts 
>> at runtime, it seems slow.
>>
>> The idea from the example is to preparse fonts with 72 fontsize, then 
>> create a a texture to be rendered.
>> Is there a better way to do this?
>>
>
>>
>> Thanks,
>> S
>>
>
> Create a glyph or text atlas invalidating, updating, paging it as needed.
>
> For a basic glyph atlas 
> https://gist.github.com/egonelbre/fbbf4651a4f75f8450fd4fc2244c283f -- you 
> can of course use multiple pages and use better layouting algorithm to 
> preserve memory.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] how dose netpollblock been awaked while sysmon slepp?

2017-04-20 Thread Ian Lance Taylor
On Thu, Apr 20, 2017 at 5:45 AM, sydnash  wrote:
>
> how did you debug the go runtime? use print or gcc, or some other tools?

Mostly by adding print statements, and tracing (see the GODEBUG
environment variable).

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ian Lance Taylor
On Thu, Apr 20, 2017 at 2:14 AM,   wrote:
>
> At the moment it is implemented as
>
>295 func IsSorted(data Interface) bool {
>296 n := data.Len()
>297 for i := n - 1; i > 0; i-- {
>298 if data.Less(i, i-1) {
>299 return false
>300 }
>301 }
>302 return true
>303 }
>
>
> Is there any practical (technical) reason for this loop to be
> end-to-beginning, or is it just a preference of someone who implemented it?

Robert wrote it in
https://github.com/golang/go/commit/18852cf6d3f23a4fbcf2756836eb929283126827
.  Let's ask him.  It was less than ten years ago.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] [ANN] sqlite

2017-04-20 Thread Jan Mercl
Early preview of a DB driver for SQLite without CGO:
https://github.com/cznic/sqlite

ATM Linux/Intel only.



-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: OpenGL Fonts

2017-04-20 Thread saif
Found an antialiased, 2D vector drawing libray.
This should work.

github.com/memononen/nanovg


Thanks,
S

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Rob Pike
Try it the other way. You'll see it's not so clean.

-rob


On Thu, Apr 20, 2017 at 7:47 PM, Ian Lance Taylor  wrote:

> On Thu, Apr 20, 2017 at 2:14 AM,   wrote:
> >
> > At the moment it is implemented as
> >
> >295 func IsSorted(data Interface) bool {
> >296 n := data.Len()
> >297 for i := n - 1; i > 0; i-- {
> >298 if data.Less(i, i-1) {
> >299 return false
> >300 }
> >301 }
> >302 return true
> >303 }
> >
> >
> > Is there any practical (technical) reason for this loop to be
> > end-to-beginning, or is it just a preference of someone who implemented
> it?
>
> Robert wrote it in
> https://github.com/golang/go/commit/18852cf6d3f23a4fbcf2756836eb92
> 9283126827
> .  Let's ask him.  It was less than ten years ago.
>
> Ian
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Large GC pauses with large map

2017-04-20 Thread 刘桂祥
try use value type
example:
map[string]*struct  => map[[20]byte]struct  

在 2017年4月20日星期四 UTC+8下午9:49:49,Lee Armstrong写道:
>
> See attached graph which shows the GC pauses of an application we have.
>
> I am frequently seeing pauses of 1-1.5 seconds. This is using Go 1.8.1 and 
> have a large map that is frequently accessed and items are removed and 
> added to it.  These can be of some size.
>
> Is there a way to get these pauses down at all?  Would forcing a GC() 
> after removing a batch of elements help at all?
>
> Alongside the pauses I see some substantial CPU usage showing up in traces 
> for the GC scan.
>
> Thanks in advance!
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Change imaginary part of a complex

2017-04-20 Thread Michael Jones
It would be natural if real(c) and imag(c) were lvalues

On Thu, Apr 20, 2017 at 1:21 PM 'Thomas Bushnell, BSG' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> The other way is to add the c to its conjugate and then add the imaginary
> part, using cmplx.Conj. But that really amounts to what you're doing
> already.
>
> On Thu, Apr 20, 2017 at 3:20 AM Val  wrote:
>
>> Hello folks
>> To keep real part of a complex, and set its imag part, I'm doing
>>   c = complex(real(c), -5.0)
>>
>> Is there a more concise way, something like   c.imag = -5.0  ? I know
>> this one doesn't compile, but I may be missing something obvious.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Michael T. Jones
michael.jo...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ivan Kurnosov
@Rob,

honestly to me they look the same:

func IsSorted(data Interface) bool {
n := data.Len()
for i := n - 1; i > 0; i-- {
if data.Less(i, i-1) {
return false
}
}
return true
}


func IsSortedForward(data sort.Interface) bool {
n := data.Len()
for i := 1; i < n; i++ {
if data.Less(i, i-1) {
return false
}
}
return true
}

https://play.golang.org/p/KSwwMk67ew

On Friday, April 21, 2017 at 2:19:26 PM UTC+12, Rob 'Commander' Pike wrote:
>
> Try it the other way. You'll see it's not so clean.
>
> -rob
>
>
> On Thu, Apr 20, 2017 at 7:47 PM, Ian Lance Taylor  > wrote:
>
>> On Thu, Apr 20, 2017 at 2:14 AM,  > wrote:
>> >
>> > At the moment it is implemented as
>> >
>> >295 func IsSorted(data Interface) bool {
>> >296 n := data.Len()
>> >297 for i := n - 1; i > 0; i-- {
>> >298 if data.Less(i, i-1) {
>> >299 return false
>> >300 }
>> >301 }
>> >302 return true
>> >303 }
>> >
>> >
>> > Is there any practical (technical) reason for this loop to be
>> > end-to-beginning, or is it just a preference of someone who implemented 
>> it?
>>
>> Robert wrote it in
>>
>> https://github.com/golang/go/commit/18852cf6d3f23a4fbcf2756836eb929283126827
>> .  Let's ask him.  It was less than ten years ago.
>>
>> Ian
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] doubt about sync.NewCond

2017-04-20 Thread Allan
I run a demo program to learn sync.NewCond:

package main

import (
   "fmt"
   "sync"
   "time"
)

var locker = new(sync.Mutex)
var cond = sync.NewCond(locker)

func test(x int) {

   cond.L.Lock() 
   cond.Wait()   
   fmt.Println(x)
   time.Sleep(time.Second * 1)
   cond.L.Unlock() 
}
func main() {
   for i := 0; i < 10; i++ {
  go test(i)
   }
   fmt.Println("start all")
   cond.Broadcast() 
   time.Sleep(time.Second * 60)
}


When I run this program on Mac(Sierra 10.12.4),it will print 0~9 randomly. 
But When I run it on Ubuntu 16.04, its result is not unique, sometime just 
print "start all", sometimes print some numbers but not all. I debug it 
with dlv, and the stack is as below:

(dlv) bt
0  0x00453693 in runtime.futex
   at /usr/local/go/src/runtime/sys_linux_amd64.s:388
1  0x004238de in runtime.futexsleep
   at /usr/local/go/src/runtime/os_linux.go:62
2  0x0040c370 in runtime.notetsleep_internal
   at /usr/local/go/src/runtime/lock_futex.go:174
3  0x0040c4e2 in runtime.notetsleepg
   at /usr/local/go/src/runtime/lock_futex.go:206
4  0x0043fff8 in runtime.timerproc
   at /usr/local/go/src/runtime/time.go:209
5  0x004525f0 in runtime.goexit
   at /usr/local/go/src/runtime/asm_amd64.s:2086
(dlv) goroutine
Thread 9327 at /usr/local/go/src/runtime/sys_linux_amd64.s:388
Goroutine 15:
Runtime: /usr/local/go/src/runtime/lock_futex.go:206 runtime.notetsleepg 
(0x40c4e2)
User: /usr/local/go/src/runtime/lock_futex.go:206 runtime.notetsleepg 
(0x40c4e2)
Go: /usr/local/go/src/runtime/time.go:97 runtime.addtimerLocked (0x43fc2e)
(dlv) goroutines
[15 goroutines]
  Goroutine 1 - User: /usr/local/go/src/runtime/time.go:59 time.Sleep 
(0x43fa55)
  Goroutine 2 - User: /usr/local/go/src/runtime/proc.go:260 runtime.gopark 
(0x4283fa)
  Goroutine 3 - User: /usr/local/go/src/runtime/proc.go:260 runtime.gopark 
(0x4283fa)
  Goroutine 4 - User: /usr/local/go/src/runtime/proc.go:260 runtime.gopark 
(0x4283fa)
  Goroutine 5 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 6 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 7 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 8 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 9 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 10 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 11 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 12 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 13 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
  Goroutine 14 - User: /usr/local/go/src/runtime/sema.go:267 
sync.runtime_notifyListWait (0x436341)
* Goroutine 15 - User: /usr/local/go/src/runtime/lock_futex.go:206 
runtime.notetsleepg (0x40c4e2) 


I'm not familiar to the raw code,can someone give me some help. Thx.

BTW: My golang version is go version go1.7.4 linux/amd64.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread andrey mirtchovski
>  297 for i := n - 1; i > 0; i-- {

"i > 0" is cheaper than "i < n" on some processors :)

On Thu, Apr 20, 2017 at 3:14 AM,   wrote:
> Hi
>
> At the moment it is implemented as
>
>295func IsSorted(data Interface) bool {
>296n := data.Len()
>297for i := n - 1; i > 0; i-- {
>298if data.Less(i, i-1) {
>299return false
>300}
>301}
>302return true
>303}
>
>
> Is there any practical (technical) reason for this loop to be
> end-to-beginning, or is it just a preference of someone who implemented it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ivan Kurnosov
Speaking low level - how about memory prefetch algorithms (os, hardware)? 
Do they work equally good when one iterates backward?

On Friday, April 21, 2017 at 3:50:39 PM UTC+12, andrey mirtchovski wrote:
>
> >  297 for i := n - 1; i > 0; i-- { 
>
> "i > 0" is cheaper than "i < n" on some processors :) 
>
> On Thu, Apr 20, 2017 at 3:14 AM,  > wrote: 
> > Hi 
> > 
> > At the moment it is implemented as 
> > 
> >295func IsSorted(data Interface) bool { 
> >296n := data.Len() 
> >297for i := n - 1; i > 0; i-- { 
> >298if data.Less(i, i-1) { 
> >299return false 
> >300} 
> >301} 
> >302return true 
> >303} 
> > 
> > 
> > Is there any practical (technical) reason for this loop to be 
> > end-to-beginning, or is it just a preference of someone who implemented 
> it? 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "golang-nuts" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to golang-nuts...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] [ANN] sqlite

2017-04-20 Thread Jérôme LAFORGE
Hello, 
It is driver only or that contains also the process that manages the data via 
sql? 
Thx in advance. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: OpenGL Fonts

2017-04-20 Thread Egon
On Friday, 21 April 2017 02:21:55 UTC+3, saif wrote:
>
> image atlas will assume that all needed fonts will fit in "image.NewRGBA
> (image.Rect(0, 0, 1024, 1024))", right?
>

Not really, there are two fixes when you fill up the image:

1. Create an new atlas for new glyphs (switching during rendering as 
necessary) -- i.e. paging
2. Clear the current image and rerender glyphs -- i.e. removing glyphs that 
haven't been used for a while.

With the 2. the whole atlas should be a grid where you add/remove glyphs as 
needed and reupload as little as possible.

To avoid expensive rasterization there must be a cache somewhere -- there 
is no escaping from it. Whether you do it per-glyph, per-text and how you 
invalidate/update are just details... annoying little details.
 

> can i can call loadglyph(), when when a rune is needed? or should i call 
> LoadGlyphs() with all possible runes during initialization?
>
> i think this will be slow, if i will initialize LoadGlyphs() with asian 
> texts, right?
>

LoadGlyphs is there to preallocate a batch of glyphs.

loadGlyph is executed only once per glyph during the lifetime of the 
program. Of course when you are using asian text I suspect you will fill up 
the atlas rather quickly.

On Thursday, April 20, 2017 at 2:52:53 PM UTC+8, Egon wrote:
>>
>> On Tuesday, 18 April 2017 08:02:02 UTC+3, saif wrote:
>>>
>>> Hi,
>>>
>>> I like to ask for your suggestions.
>>>
>>> I found a nice project, and was trying to modify them but got stuck with 
>>> fonts.
>>> (github.com/dskinner/material)
>>>
>>> I like the fonts to be configurable, but when I tried to parse the fonts 
>>> at runtime, it seems slow.
>>>
>>> The idea from the example is to preparse fonts with 72 fontsize, then 
>>> create a a texture to be rendered.
>>> Is there a better way to do this?
>>>
>>
>>>
>>> Thanks,
>>> S
>>>
>>
>> Create a glyph or text atlas invalidating, updating, paging it as needed.
>>
>> For a basic glyph atlas 
>> https://gist.github.com/egonelbre/fbbf4651a4f75f8450fd4fc2244c283f -- 
>> you can of course use multiple pages and use better layouting algorithm to 
>> preserve memory.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.