Beispiel #1
0
int main()
{
  REPORT_MISC("exec_basic_helper main() starting...");
  REPORT_END_SUCCESS;
 
  exit(1);
}
Beispiel #2
0
void * chase(void * arg) {
  int next_mutex_to_acquire = 0;
  int highest_mutex_released = -1;
  // we don't want behavior to be determined by thread id policy, use
  // 0..n_chasethreads-1 here (passed in as argument)
  int my_creation_number = (int)arg;
  char buf[80];

  snprintf(buf, sizeof (buf), "Starting chase thread with creation number %d",
           my_creation_number);
  REPORT_MISC(buf);

  while (highest_mutex_released < n_mutexes - 1) {

    // if we haven't acquired mutexes all the way to the end of the array,
    // acquire one more
    if (next_mutex_to_acquire < n_mutexes) {
		mutex_lock(&(mtxs[next_mutex_to_acquire++]));
    }

    // TODO: here's the point that we 'periodically do something' such as
    // sleep() or yield()
    if (((my_creation_number % STUPID_MAGIC_CONSTANT) == 0)
        && ((highest_mutex_released % STUPID_MAGIC_CONSTANT) == 0)) {
      yield(-1);	
    }
    // we only start releasing mutexes when we've acquired a total of
    // "footprint" mutexes
    if (next_mutex_to_acquire >= footprint) {
      mutex_unlock(&(mtxs[++highest_mutex_released]));
    }
  }

  snprintf(buf, sizeof (buf),
           "Successful finish for thread with creation number %d",
           my_creation_number);
  REPORT_MISC(buf);

  return (void *)1;
}