Kizingiti (tarakilishi)

Katika utarakilishi, kizingiti ni jinsi ya ulandanishi (kwa Kiingereza: barrier in computer science). Neno kizingiti linamaanisha kwamba amri ya tarakilishi haiwezi kuendelea ikiwa amri za awali hazifanyiki.

Amri hii ya C++ inatumia vizingiti :

struct barrier_type

{

    // how many processors have entered the barrier

    // initialize to 0

    int arrive_counter;

    // how many processors have exited the barrier

    // initialize to p

    int leave_counter;

    int flag;

    std::mutex lock;

};


// barrier for p processors

void barrier(barrier_type* b, int p)

{

    b->lock.lock();

    if (b->leave_counter == p)

    {

        if (b->arrive_counter == 0) // no other threads in barrier

        {

            b->flag = 0; // first arriver clears flag

        }

        else

        {

            b->lock.unlock();

            while (b->leave_counter != p); // wait for all to leave before clearing

            b->lock.lock();

            b->flag = 0; // first arriver clears flag

        }

    }

    b->arrive_counter++;

    int arrived = b->arrive_counter;

    b->lock.unlock();

    if (arrived == p) // last arriver sets flag

    {

        b->arrive_counter = 0;

        b->leave_counter = 1;

        b->flag = 1;

    }

    else

    {

        while (b->flag == 0); // wait for flag

        b->lock.lock();

        b->leave_counter++;

        b->lock.unlock();

    }

}

Marejeo

hariri
  • Petzell, M. (2005). Expanding the Swahili vocabulary. Africa & Asia, 5, 85-107.
  Makala hii kuhusu mambo ya teknolojia bado ni mbegu.
Je, unajua kitu kuhusu mada hiyo kama historia yake au mahusiano yake na mada nyingine?
Labda unaona habari katika Wikipedia ya Kiingereza au lugha nyingine zinazofaa kutafsiriwa?
Basi unaweza kuisaidia Wikipedia kwa kuihariri na kuongeza habari.