github.com/tursom/GoCollections@v0.3.10/concurrent/ReentrantRWLock_test.go (about)

     1  /*
     2   * Copyright (c) 2022 tursom. All rights reserved.
     3   * Use of this source code is governed by a GPL-3
     4   * license that can be found in the LICENSE file.
     5   */
     6  
     7  package concurrent
     8  
     9  import (
    10  	"fmt"
    11  	"testing"
    12  
    13  	"github.com/tursom/GoCollections/util/time"
    14  )
    15  
    16  func TestReentrantRWLock_RLock(t *testing.T) {
    17  	lock := NewReentrantRWLock()
    18  	lock.Lock()
    19  	defer lock.Unlock()
    20  
    21  	go func() {
    22  		lock.Lock()
    23  		defer lock.Unlock()
    24  		fmt.Println("get lock")
    25  	}()
    26  	time.Sleep(time.Second)
    27  	lock.Lock()
    28  	defer lock.Unlock()
    29  	lock.RLock()
    30  	defer lock.RUnlock()
    31  	lock.RLock()
    32  	defer lock.RUnlock()
    33  	fmt.Println("release lock")
    34  }