3
�
�^�p c @ s d Z ddlZddlZddlmZmZ ddlZddlZddlZddl m
Z
dd� ZG dd� de�Z
G d d
� d
ej�ZG dd� de�ZG d
d� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZdS )z/
Various tests for synchronization primitives.
� N)�start_new_thread�TIMEOUT_MAX)�supportc C s t jd� d S )N�{�G�z�?)�time�sleep� r r �'/usr/lib64/python3.6/test/lock_tests.py�_wait s r c @ s2 e Zd ZdZddd�Zdd� Zdd� Zd d
� ZdS )
�Bunchz
A bunch of threads.
Fc
s| � �_ |�_g �_g �_| �_tj� �_�jj� � �fdd�}y xt |�D ]}t
|f � qNW W n d�_� Y nX dS )z�
Construct a bunch of `n` threads running the same function `f`.
If `wait_before_exit` is True, the threads won't terminate until
do_finish() is called.
c sD t j� } �jj| � z
� � W d �jj| � x�js<t� q.W X d S �N)� threadingZ get_ident�started�append�finished� _can_exitr )Ztid��f�selfr r �task% s
zBunch.__init__.<locals>.taskTN)r �nr
r r r �wait_threads_exit�wait_threadZ __enter__�ranger )r r r Zwait_before_exitr �ir r r �__init__ s
zBunch.__init__c C s xt | j�| jk rt� qW d S r )�lenr
r r �r r r r �wait_for_started6 � zBunch.wait_for_startedc C s0 xt | j�| jk rt� qW | jjd d d � d S r )r r r r r Z__exit__r r r r �wait_for_finished: s
zBunch.wait_for_finishedc C s
d| _ d S �NT)r r r r r � do_finish@ � zBunch.do_finishN)F)�__name__�
__module__�__qualname__�__doc__r r r r! r r r r r
s
r
c @ s$ e Zd Zdd� Zdd� Zdd� ZdS )�BaseTestCasec C s t j� | _d S r )r Zthreading_setup�_threadsr r r r �setUpE r"