示例#1
0
void *P0(void *arg)
{
  long int EAX, EBX;
  z = 2;
  MFENCE();
  EAX = x;
  return (void*)(EAX==0);
}
示例#2
0
void *P0(void *arg)
{
  long int EAX, EBX;
  y = 1;
  MFENCE();
  EAX = x;
  printf("\n (EAX0=%d) \n", EAX); 
  return (void*)(EAX==0);
}
示例#3
0
/**
 * Enter a critical section. Implementation using Algorithm2 (mutex_lab3).
 *
 * \param thread Thread ID, either 0 or 1.
 */
static void
impl_enter_critical(int thread)
{
        assert(thread == 0 || thread == 1);

        /* HINT: Since Algorithm2 only works for 2 threads,
         * with the ID 0 and 1, you may use !thread to get the ID the
         * other thread. */
        flag[thread] = 1;
        MFENCE();
        while (flag[!thread]) {
            if (turn != thread) {
                flag[thread] = 0;
                while (turn != thread);
                flag[thread] = 1;
                MFENCE();
            }
        }
}
示例#4
0
// Consumer
void * BlockOnIdle(void * arg)
{
    obtain_lock(__unbuffered_condVariable);
    isIdling = 1;
    //fence;
    MFENCE();
    if(!hasWork)
	Wait(__unbuffered_condVariable);
    isIdling = 0;
    release_lock(__unbuffered_condVariable);
}
示例#5
0
// Producer
void * NotifyPotentialWork(void * arg)
{
    hasWork = 1;
    //fence;
    MFENCE();
    if(isIdling)
    {
	obtain_lock(__unbuffered_condVariable);
	Pulse(__unbuffered_condVariable);
	release_lock(__unbuffered_condVariable);
    }
    __unbuffered_prod_done=1;
}