???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................ó
¿œ^c           @   s»   d  d l  Z  d d d „  ƒ  YZ d d d „  ƒ  YZ d d d „  ƒ  YZ d d d	 „  ƒ  YZ d
 d d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e d k r· e ƒ  n  d S(   iÿÿÿÿNt	   conditionc           B   sD   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c         C   s­   | d  k r t j ƒ  |  _ n3 t | d ƒ rH t | d ƒ rH | |  _ n	 t d ‚ t j ƒ  |  _ |  j j ƒ  t j ƒ  |  _ d |  _	 d |  _
 d |  _ d |  _ d |  _ d  S(   Nt   acquiret   releases.   condition constructor requires a lock argumenti    (   t   Nonet   threadt   allocate_lockt   mutext   hasattrt	   TypeErrort   checkoutR   t   idlockt   idt   waitingt   pendingt	   toreleaset	   releasing(   t   selft   lock(    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   __init__  s    					c         C   s   |  j  j ƒ  d  S(   N(   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   *  s    c         C   s   |  j  j ƒ  d  S(   N(   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   -  s    c         C   s3  |  j  |  j |  j } } } | j ƒ  s5 t d ‚ n  | j ƒ  |  j } |  j d |  _ | j ƒ  | j ƒ  x? | j ƒ  | j ƒ  | |  j k  r– Pn  | j ƒ  | j ƒ  qo W|  j	 d |  _	 |  j
 d |  _
 |  j
 rä | j ƒ  n7 d |  _ |  j	 |  j k o
d k n rd |  _ n  | j ƒ  | j ƒ  d  S(   Ns1   condition must be .acquire'd when .wait() invokedi   i    (   R   R	   R
   t   lockedt
   ValueErrorR   R   R   R   R   R   R   (   R   R   R	   R
   t   myid(    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   wait0  s2    	
	


 

 		"
c         C   s   |  j  d ƒ d  S(   Ni   (   t	   broadcast(   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   signalN  s    iÿÿÿÿc         C   sè   | d k  r t  d | f ‚ n  | d k r/ d  S|  j j ƒ  |  j rt |  j |  j |  _ d |  _ |  j d |  _ n  | d k r |  j |  _ n t |  j |  j | ƒ |  _ |  j r× |  j r× d |  _ |  j	 j
 ƒ  n  |  j j
 ƒ  d  S(   Niÿÿÿÿs   .broadcast called with num %ri    i   (   R   R
   R   R   R   R   R   t   minR   R	   R   (   R   t   num(    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   Q  s"    				N(	   t   __name__t
   __module__R   R   R   R   R   R   R   (    (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR      s   				t   barrierc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s"   | |  _  | |  _ t ƒ  |  _ d  S(   N(   t   nt   togoR    t   full(   R   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   f  s    		c         C   s]   |  j  } | j ƒ  |  j d |  _ |  j r9 | j ƒ  n |  j |  _ | j ƒ  | j ƒ  d  S(   Ni   (   R    R   R   R   R   R   R   (   R   R    (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   enterk  s    	
	
(   R   R   R   R!   (    (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   e  s   	t   eventc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   d |  _  t ƒ  |  _ d  S(   Ni    (   t   stateR    t   posted(   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   w  s    	c         C   s4   |  j  j ƒ  d |  _ |  j  j ƒ  |  j  j ƒ  d  S(   Ni   (   R$   R   R#   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   post{  s    	c         C   s'   |  j  j ƒ  d |  _ |  j  j ƒ  d  S(   Ni    (   R$   R   R#   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   clear  s    	c         C   s'   |  j  j ƒ  |  j } |  j  j ƒ  | S(   N(   R$   R   R#   R   (   R   t   answer(    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt	   is_posted†  s    	c         C   s7   |  j  j ƒ  |  j s& |  j  j ƒ  n  |  j  j ƒ  d  S(   N(   R$   R   R#   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   Œ  s    	(   R   R   R   R%   R&   R(   R   (    (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR"   v  s
   				t	   semaphorec           B   s&   e  Z d  d „ Z d „  Z d „  Z RS(   i   c         C   s>   | d k r t  d | ‚ n  | |  _ | |  _ t ƒ  |  _ d  S(   Ni    s    semaphore count %d; must be >= 1(   R   t   countt   maxcountR    t   nonzero(   R   R*   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   “  s
    		c         C   sQ   |  j  j ƒ  x  |  j d k r/ |  j  j ƒ  q W|  j d |  _ |  j  j ƒ  d  S(   Ni    i   (   R,   R   R*   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   pš  s
    c         C   s`   |  j  j ƒ  |  j |  j k r2 t d |  j ‚ n  |  j d |  _ |  j  j ƒ  |  j  j ƒ  d  S(   Ns:   .v() tried to raise semaphore count above initial value %ri   (   R,   R   R*   R+   R   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   v¡  s    (   R   R   R   R-   R.   (    (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR)   ’  s   	t   mrswc           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sR   t  j ƒ  |  _ d |  _ d |  _ d |  _ t |  j ƒ |  _ t |  j ƒ |  _ d  S(   Ni    (	   R   R   t   rwOKt   nrt   nwt   writingR    t   readOKt   writeOK(   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR   «  s    			c         C   sK   |  j  j ƒ  x |  j r) |  j j ƒ  q W|  j d |  _ |  j  j ƒ  d  S(   Ni   (   R0   R   R2   R4   R   R1   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   read_in¶  s
    c         C   sh   |  j  j ƒ  |  j d k r( t d ‚ n  |  j d |  _ |  j d k rW |  j j ƒ  n  |  j  j ƒ  d  S(   Ni    s,   .read_out() invoked without an active readeri   (   R0   R   R1   R   R5   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   read_out½  s    	c         C   s]   |  j  j ƒ  |  j d |  _ x# |  j s2 |  j rB |  j j ƒ  q  Wd |  _ |  j  j ƒ  d  S(   Ni   (   R0   R   R2   R3   R1   R5   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   write_inÇ  s    	c         C   sr   |  j  j ƒ  |  j s" t d ‚ n  d |  _ |  j d |  _ |  j rT |  j j ƒ  n |  j j ƒ  |  j  j	 ƒ  d  S(   Ns-   .write_out() invoked without an active writeri    i   (
   R0   R   R3   R   R2   R5   R   R4   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt	   write_outÏ  s    				c         C   su   |  j  j ƒ  |  j s" t d ‚ n  d |  _ |  j d |  _ |  j d |  _ |  j sd |  j j ƒ  n  |  j  j ƒ  d  S(   Ns1   .write_to_read() invoked without an active writeri    i   (	   R0   R   R3   R   R2   R1   R4   R   R   (   R   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   write_to_readÜ  s    				(   R   R   R   R6   R7   R8   R9   R:   (    (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyR/   ª  s   			
		c         G   sy   t  j ƒ  t d } a t  j ƒ  t j ƒ  t j | ƒ d G| Gd Gt t ƒ Gd GHt j ƒ  t j	 |  | f | ƒ d  S(   Ni   s   starting threads   --t   alive(
   t   tidR   t   TIDR   t   ioR;   t   appendt   lenR   t   start_new_thread(   t   funct   argsR   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   _new_threadï  s    
  

 
c   
      C   sW  t  j ƒ  d G|  Gd G| G| GHt  j ƒ  | | d k r| | } | d } xQ t | | ƒ D]@ } | | | k r] | | | | | | <| | <| d } q] q] W| | d | | | <| | d <t ƒ  } t ƒ  }	 t t | | | d | ƒ t t | | | |	 ƒ | j ƒ  |	 j ƒ  n  t  j ƒ  d G|  Gd GHt j	 |  ƒ t  j ƒ  | j
 ƒ  d  S(   NR   t   qsorti   s
   qsort done(   R>   R   R   t   rangeR"   RD   t   _qsortR   R;   t   removeR%   (
   R<   t   at   lt   rt   finishedt   pivott   jt   it   l_subarray_sortedt   r_subarray_sorted(    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyRG   ÷  s,    
  


!		

  
c         C   s½   t  j ƒ  d G|  Gd GHt  j ƒ  x] t d t | ƒ ƒ D]F } t j ƒ  t d | ƒ } t j ƒ  | | | | | | <| | <q7 Wt  j ƒ  d G|  Gd GHt j |  ƒ t  j ƒ  | j	 ƒ  d  S(   NR   s   randomizing arrayi   i    s   randomizing done(
   R>   R   R   RF   R@   t   wht   randintR;   RH   R%   (   R<   RI   RL   RO   RN   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt
   _randarray  s    
 

  
!
  
c         C   s.   |  t  t |  ƒ ƒ k r* t d |  f ‚ n  d  S(   Ns   a not sorted(   RF   R@   R   (   RI   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   _check_sort  s    c         C   s6  t  j ƒ  d G|  Gd G| GHt  j ƒ  t ƒ  } t t | | ƒ | j ƒ  t  j ƒ  d G|  Gd G| GHt  j ƒ  | j ƒ  t t | d t	 | ƒ | ƒ | j ƒ  t
 | ƒ t  j ƒ  d G|  Gd GHt  j ƒ  | j ƒ  t  j ƒ  d G|  Gd GHt  j ƒ  t  j ƒ  t j |  ƒ t  j ƒ  | j ƒ  | j ƒ  | j ƒ  d  S(   NR   t   randomizingt   sortingi    s   entering barriers   leaving barrier(   R>   R   R   R"   RD   RT   R   R&   RG   R@   RU   R!   R;   RH   R%   (   R<   RI   t   bart   doneRL   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   _run_one_sort  s4    
 
	

  




 


 

  


c          C   sX  d d  l  }  |  j a d a t j ƒ  a t j ƒ  a t j ƒ  a g  a d } g  } x/ t	 | ƒ D]! } | j
 t	 | d d ƒ ƒ q^ Wt | ƒ } t ƒ  } x+ t	 | ƒ D] } t t | | | | ƒ q¥ W| j ƒ  d GHt rí t d t f ‚ n  xW t	 | ƒ D]I } | | } t | ƒ | d d k r9t d | d	 f ‚ n  t | ƒ qú Wd
 Gt Gd GHd  S(   Niÿÿÿÿi    i   i   i
   s*   all threads done, and checking results ...s   threads still alive at ends   length of arrays
   screwed ups   test passed!s   threads created in all(   t   randomRS   R=   R   R   R<   R>   RR   R;   RF   R?   R   R"   RD   RZ   R   R   R@   RU   (   R[   t   NSORTSt   arraysRO   RX   RL   RI   (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   test7  s2    		

t   __main__(    (    (    (    (    (   R   R    R   R"   R)   R/   RD   RG   RT   RU   RZ   R^   R   (    (    (    s)   /usr/lib64/python2.7/Demo/threads/sync.pyt   <module>  s   TE			
			!