Ignore:
Timestamp:
Feb 13, 2017, 5:04:43 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ee897e4b
Parents:
75f3522
Message:

Implemented better condition lock to solve race condition on thread/processor termination

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel

    r75f3522 rdb6f06a  
    2727
    2828//-----------------------------------------------------------------------------
     29// Locks
     30// void lock( simple_lock * );
     31// void lock( simple_lock *, spinlock * );
     32// void unlock( simple_lock * );
     33
     34void lock( spinlock * );
     35void unlock( spinlock * );
     36
     37void wait( signal_once * );
     38void signal( signal_once * );
     39
     40//-----------------------------------------------------------------------------
    2941// Cluster
    3042struct cluster {
    3143        simple_thread_list ready_queue;
    32         // pthread_spinlock_t lock;
     44        spinlock lock;
    3345};
    3446
     
    3850//-----------------------------------------------------------------------------
    3951// Processor
    40 enum ProcessorAction {
    41         Reschedule,
    42         NoAction
     52enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule };
     53struct FinishAction {
     54        FinishOpCode action_code;
     55        thread * thrd;
     56        spinlock * lock;
    4357};
     58static inline void ?{}(FinishAction * this) {
     59        this->action_code = No_Action;
     60        this->thrd = NULL;
     61        this->lock = NULL;
     62}
     63static inline void ^?{}(FinishAction * this) {}
    4464
    4565struct processor {
     
    4969        thread * current_thread;
    5070        pthread_t kernel_thread;
    51         simple_lock lock;
    52         volatile bool terminated;
    53         ProcessorAction thread_action;
     71       
     72        signal_once terminated;
     73        volatile bool is_terminated;
     74
     75        struct FinishAction finish;
    5476};
    5577
     
    5779void ?{}(processor * this, cluster * cltr);
    5880void ^?{}(processor * this);
    59 
    60 //-----------------------------------------------------------------------------
    61 // Locks
    62 
    63 void ?{}(simple_lock * this);
    64 void ^?{}(simple_lock * this);
    65 
    66 void lock( simple_lock * );
    67 void unlock( simple_lock * );
    6881
    6982#endif //KERNEL_H
Note: See TracChangeset for help on using the changeset viewer.