class_docstr: A lock to allow many members of a group to access a resource exclusively.
  
  This lock provides a way to allow access to a resource by multiple threads
  belonging to a logical group at the same time, while restricting access to
  threads from all other groups. You can think of this as an extension of a
  reader-writer lock, where you allow multiple writers at the same time. We
  made it generic to support multiple groups instead of just two - readers and
  writers.
  
  Simple usage example with two groups accessing the same resource:
  
  ```python
  lock = GroupLock(num_groups=2)
  
  # In a member of group 0:
  with lock.group(0):
    # do stuff, access the resource
    # ...
  
  # In a member of group 1:
  with lock.group(1):
    # do stuff, access the resource
    # ...
  ```
  
  Using as a context manager with `.group(group_id)` is the easiest way. You
  can also use the `acquire` and `release` method directly.
docstr: Initialize a group lock.
  
  Args:
    num_groups: The number of groups that will be accessing the resource under
      consideration. Should be a positive number.
  
  Returns:
    A group lock that can then be used to synchronize code.
  
  Raises:
    ValueError: If num_groups is less than 1.
code: def __init__(self, num_groups=2):
      """Initialize a group lock.
  
      Args:
        num_groups: The number of groups that will be accessing the resource under
          consideration. Should be a positive number.
  
      Returns:
        A group lock that can then be used to synchronize code.
  
      Raises:
        ValueError: If num_groups is less than 1.
      """
      if num_groups < 1:
          raise ValueError(
              "Argument `num_groups` must be a positive integer. "
              f"Received: num_groups={num_groups}"
          )
      self._ready = threading.Condition(threading.Lock())
      self._num_groups = num_groups
      self._group_member_counts = [0] * self._num_groups
  
file_path: tensorflow-upstream/tensorflow/python/util/lock_util.py
imports: import threading
label_desc: Use image node_id 1 to create a new GroupLock object from inherited base classes: object with example: obj = GroupLock(num_groups)