Github user huaiyun commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/1028#discussion_r71634947
  
    --- Diff: lib/go/thrift/simple_server.go ---
    @@ -149,8 +151,10 @@ func (p *TSimpleServer) Serve() error {
     }
     
     func (p *TSimpleServer) Stop() error {
    -   p.quit <- struct{}{}
    -   p.serverTransport.Interrupt()
    +   if atomic.CompareAndSwapInt64(&p.stopped, 0, 1) {
    --- End diff --
    
    @jeking3 
    The CompareAndSwapInt64 will return true of false to mark if the counter 
has been swapped.
    
    the golang doc:
    // The compare-and-swap operation, implemented by the CompareAndSwapT
    // functions, is the atomic equivalent of:
    //
    //      if *addr == old {
    //              *addr = new
    //              return true
    //      }
    //      return false
    
    At the first call, it returns true. Because the counter is 0 as 
initialized, and will be swapped to 1.
    At the second call or more, it will return false. Because the counter is 
already 1, not 0.
    So this make the Stop() only works at the first call. The more will be 
skipped.
    
    a simple function is here:
    https://play.golang.org/p/s-yHhQHG_O


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to