Changeset 4fc3343


Ignore:
Timestamp:
Jan 18, 2021, 1:32:01 PM (8 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
978e5eb, efdfdee
Parents:
78a8440
Message:

Fix race with memory reclamation of io_context.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/io/setup.cfa

    r78a8440 r4fc3343  
    113113
    114114        static struct {
    115                 pthread_t       thrd;    // pthread handle to io poller thread
    116                 void *          stack;   // pthread stack for io poller thread
    117                 int             epollfd; // file descriptor to the epoll instance
    118                 volatile bool   run;     // Whether or not to continue
    119                 volatile size_t epoch;   // Epoch used for memory reclamation
     115                      pthread_t  thrd;    // pthread handle to io poller thread
     116                      void *     stack;   // pthread stack for io poller thread
     117                      int        epollfd; // file descriptor to the epoll instance
     118                volatile     bool run;     // Whether or not to continue
     119                volatile     bool stopped; // Whether the poller has finished running
     120                volatile uint64_t epoch;   // Epoch used for memory reclamation
    120121        } iopoll;
    121122
     
    130131                __cfadbg_print_safe(io_core, "Kernel : Starting io poller thread\n" );
    131132
    132                 iopoll.run = true;
    133                 iopoll.stack = __create_pthread( &iopoll.thrd, iopoll_loop, 0p );
    134                 iopoll.epoch = 0;
     133                iopoll.stack   = __create_pthread( &iopoll.thrd, iopoll_loop, 0p );
     134                iopoll.run     = true;
     135                iopoll.stopped = false;
     136                iopoll.epoch   = 0;
    135137        }
    136138
     
    205207                        }
    206208                }
     209
     210                __atomic_store_n(&iopoll.stopped, true, __ATOMIC_SEQ_CST);
    207211
    208212                __cfadbg_print_safe(io_core, "Kernel : IO poller thread stopping\n" );
     
    536540
    537541                // Wait for the next epoch
    538                 while(curr == __atomic_load_n(&iopoll.epoch, __ATOMIC_RELAXED)) yield();
     542                while(curr == iopoll.epoch && !iopoll.stopped) Pause();
    539543        }
    540544
Note: See TracChangeset for help on using the changeset viewer.