예제 #1
0
//thread for write operations
void *threadwritelock(void *vargp)
{
	printf("%s\n", "Wait for writing!");
	rwlock_lockWrite(&rwl); //write lock
	printf("%s\n", "Writing.....");
	i = i + 1; //increase value
    //rwlock_getInfo(&rwl);

	rwlock_unlock(&rwl); //write unlock

    return NULL;
}
예제 #2
0
파일: testb.c 프로젝트: Tandrial/AI-SE-Bsc
static void *writer3(void *arg) {    
  rwlock_lockWrite(&filelock);
  printf("Writer 3 working...\n");
  fp = fopen("testb.txt","a");
  if (fp == NULL) {
    printf("Error trying to open testb.txt\n");
    return NULL;
  }

  int i;
  for(i = 200; i < 300; i++) {
    fprintf(fp,"%d w3\n",i);
    if (i % 20 == 0)
      sleep(1);
  }
  fclose(fp);
  printf("Writer 3 done.\n");
  rwlock_unlock(&filelock);
  return NULL;
}
예제 #3
0
파일: testa.c 프로젝트: Tandrial/AI-SE-Bsc
static void *writer(void *arg) {      
  int c;
  // 2 Runden
  for(c = 0;c <2; c++){
    // Writelock aktiv
    rwlock_lockWrite(&varlock);
    printf("Writer incrementing...\n");  
    //hochzählen
    int i;
    for(i = 0; i < 100; i++) {
      count++;          
    }
    printf("Writer waiting...\n");
    //Writelock weg
    rwlock_unlock(&varlock);
    sleep(1);
  }
  printf("Writer done.\n");
   return NULL;
}
예제 #4
0
파일: testb.c 프로젝트: Tandrial/AI-SE-Bsc
// 3 mal dasselbe für writer1..3
static void *writer1(void *arg) {      
  //Writelock anfordern
  rwlock_lockWrite(&filelock);
  printf("Writer 1 working...\n");
  //Datei öffnen ...
  fp = fopen("testb.txt","a");
  if (fp == NULL) {
    printf("Error trying to open testb.txt\n");
    return NULL;
  }
  //Zahlen schreiben
  int i;
  for(i = 0; i < 100; i++) {
    fprintf(fp,"%d w1\n",i);
    if (i % 20 == 0)
      sleep(1);
  }
  fclose(fp);
  printf("Writer 1 done.\n");
  //Writelock weg
  rwlock_unlock(&filelock);

   return NULL;
}