Ignore:
Timestamp:
Nov 18, 2020, 2:28:02 PM (13 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
69d1748
Parents:
9d6e1b8a
Message:

Added more checks for thread termination synchronization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/monitor.cfa

    r9d6e1b8a r3ea8ad1  
    142142static void __dtor_enter( $monitor * this, fptr_t func, bool join ) {
    143143        $thread * thrd = active_thread();
     144        #if defined( __CFA_WITH_VERIFY__ )
     145                bool is_thrd = this == &thrd->self_mon;
     146        #endif
    144147
    145148        // Lock the monitor spinlock
     
    155158                __set_owner( this, thrd );
    156159
    157                 verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     160                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     161                /* paranoid */ verify( !is_thrd || thrd->state == Halted || thrd->state == Cancelled );
    158162
    159163                unlock( this->lock );
     
    175179                __set_owner( this, thrd );
    176180
    177                 verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     181                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     182                /* paranoid */ verify( !is_thrd || thrd->state == Halted || thrd->state == Cancelled );
    178183
    179184                unlock( this->lock );
    180185                return;
    181186        }
     187
     188        // The monitor is busy, if this is a thread and the thread owns itself, it better be active
     189        /* paranoid */ verify( !is_thrd || this->owner != thrd || (thrd->state != Halted && thrd->state != Cancelled) );
    182190
    183191        __lock_size_t count = 1;
     
    209217                // Some one was waiting for us, enter
    210218                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     219
     220                __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);
     221                return;
    211222        }
    212223        else {
     
    228239                return;
    229240        }
    230 
    231         __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);
    232 
    233241}
    234242
     
    294302
    295303        /* paranoid */ verifyf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", thrd, this->owner, this->recursion, this );
    296         /* paranoid */ verify( thrd->state == Halted );
     304        /* paranoid */ verify( thrd->state == Halting );
    297305        /* paranoid */ verify( this->recursion == 1 );
    298306
     
    303311        // Fetch the next thread, can be null
    304312        $thread * new_owner = next_thread( this );
     313
     314        // Mark the state as fully halted
     315        thrd->state = Halted;
    305316
    306317        // Release the monitor lock
Note: See TracChangeset for help on using the changeset viewer.