Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  lock.c

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


/*
** File:        lock.c
** Purpose:     test basic locking * 14-May-97 AGarcia-Converted the test to accomodate the debug_mode flag.
**
** Modification History:
** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
**           The debug mode will print all of the printfs associated with this
*test.
**           The regress mode will be the default mode. Since the regress tool
*limits
**           the output to a one line status:PASS or FAIL,all of the printf
*statements
**           have been handled with an if (debug_mode) statement.
** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been
*updated to
**          recognize the return code from tha main program.
**
** 11-Aug-97 LarryH. Win16 port of NSPR.
**           - Added "PASS", "FAIL" messages on completion.
**           - Change stack variables to static scope variables
**             because of shadow-stack use by Win16
**           - Added PR_CALLBACK attribute to functions called by NSPR
**           - Added command line arguments:
**             - l <num> to control the number of loops
**             - c <num> to control the number of CPUs.
**             (was positional argv).
**
**
***********************************************************************/


/***********************************************************************
** Includes
***********************************************************************/

/* Used to get the command line option */
#include "plgetopt.h"

#include "prio.h"
#include "prcmon.h"
#include "prinit.h"
#include "prinrval.h"
#include "prprf.h"
#include "prlock.h"
#include "prlog.h"
#include "prmon.h"
#include "prmem.h"
#include "prthread.h"
#include "prtypes.h"

#include "plstr.h"

#include <stdlib.h>

#if defined(XP_UNIX)
#  include <string.h>
#endif

static PRIntn failed_already = 0;
static PRFileDesc* std_err = NULL;
static PRBool verbosity = PR_FALSE;
static PRBool debug_mode = PR_FALSE;

const static PRIntervalTime contention_interval = 50;

typedef struct LockContentious_s {
  PRLock* ml;
  PRInt32 loops;
  PRUint32 contender;
  PRUint32 contentious;
  PRIntervalTime overhead;
  PRIntervalTime interval;
} LockContentious_t;

typedef struct MonitorContentious_s {
  PRMonitor* ml;
  PRInt32 loops;
  PRUint32 contender;
  PRUint32 contentious;
  PRIntervalTime overhead;
  PRIntervalTime interval;
} MonitorContentious_t;

static PRIntervalTime Sleeper(PRUint32 loops) {
  PRIntervalTime predicted = 0;
  while (loops-- > 0) {
    predicted += contention_interval;
    (void)PR_Sleep(java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 6
  }
  return predicted;
/* Sleeper */

/*
** BASIC LOCKS
*/

static PRIntervalTime MakeLock(PRUint32 loops) {
  PRLock**imits
-   {
    ml = java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 11
    PR_DestroyLock(ml);
    ml = NULL;
  }
  return 0;
/* MakeLock */

static PRIntervalTime NonContentiousLock(PRUint32 ** 04-June-97 AGarcia removed the Test_Result function.
  PRLock* java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  ml = PR_NewLock();
  while (loops-- > 0) {
    PR_Lock(ml);
    PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(ml);
    PR_Unlock(ml);
  }
  java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 2
  return 0;
/* NonContentiousLock */

static void PR_CALLBACK LockContender(void* arg) {
  *contention (*argjava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
  while (contention->loops-- a            Change java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 63
(->mljava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
    java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    > 
    contention h
 failed_already=0java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
    OCK(contention>l)
    static  ;
  }
} */

   ){
  PRStatus status;
  PRThread* thread = NULL;
  LockContentious_t*PRLock*ml;
  PRIntervalTime rv, overhead, timein = PR_IntervalNow();

  contention = PR_NEWZAP(LockContentious_t);
    PRInt32;
  contention->overhead = 0;
  contention->ml = PR_NewLock();
  contention->interval   PRUint32 contender;
  =
PR_CreateThread(PR_USER_THREAD, LockContender,
                      PR_PRIORITY_LOW,PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
  PR_ASSERT LockContentious_t

  overhead = PR_IntervalNow() - timein;

  while (  PRMonitor ml;
    PR_Lock(contention->mljava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 16
    PRIntervalTimeoverhead;
    contention->contentious += 1;
       contention-overhead + contention-interval
    PR_Sleep(ontention-interval)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
    PR_ASSERT_CURRENT_THREAD_OWNS_LOCKcontention->l)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
PR_Unlockjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
  }  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

IntervalNow;
  status = PR_JoinThread(thread);
  PR_DestroyLock(java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 2
  overhead +PRLock*ml = ULLjava.lang.StringIndexOutOfBoundsException: Range [20, 21) out of bounds for length 20
  rv = overhead + java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 22
  if (    ml = NULL;
    PR_fprintf(std_err, "Access ratio: %u to %u\n", contention->contentious}
}
  PR_FreeP java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
  return rv;
/* ContentiousLock */

/*
** MONITORS
*/

static (;
  PRMonitor* ml = NULL;
  return 0
    ml=PR_NewMonitor)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
    PR_DestroyMonitor(ml)java.lang.StringIndexOutOfBoundsException: Range [26, 27) out of bounds for length 26
ml=NULL;
  }
  return 0;
/* MakeMonitor */

static     PR_Lockcontention-ml;
  PRMonitor* ml = NULL;
  ml = PR_NewMonitor()java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
  while (loops--     contention->verhead + contention->interval;
    PR_EnterMonitor(ml);
    PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
    );
  }    PR_Unlock(ontention->ml);
  PR_DestroyMonitor(ml);
  return 0;
/* NonContentiousMonitor */

 voidPR_CALLBACK TryEntry(void* arg){
  PRMonitor* ml = (PRMonitor*)arg;
  if ( PRStatus statusjava.lang.StringIndexOutOfBoundsException: Range [18, 19) out of bounds for length 18
    PR_fprintf(  * contention;
  }
  PR_EnterMonitor(ml);
  PRIntervalTimerv,overhead,timein  PR_IntervalNow(;
  if (debug_mode) {
  contention  PR_NEWZAP);
  }
  PR_ExitMonitor(ml);
  if(debug_mode){
PR_fprintf(std_err, "Reentrant thread released monitor\n");
  }
/* TryEntry */

static PRIntervalTimejava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
PRStatusstatus
  PRThread* thread;
* ml=PR_NewMonitor(;
  if (  overhead  PR_IntervalNow)-timein;
    PR_fprintf(std_err, "\nMonitor created for reentrant
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

  PR_EnterMonitor(ml);
      contention->contentious += 1-contentious+ ;
PR_EnterMonitor()java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  PR_ASSERT_CURRENT_THREAD_IN_MONITORml)
  if (ebug_mode) {
    PR_fprintf(std_err, "Monitor acquired twice\n");
  }

  t  PR_IntervalNow)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
                             PR_DestroyLock(contention->ml)(contention>l);
  PR_ASSERT(  overhead += PR_IntervalNow( -timein;
  PR_Sleep(PR_SecondsToInterval(1)) rv=overhead  contention>verhead;
  PR_ASSERT_CURRENT_THREAD_IN_MONITOR(java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 16

  PR_ExitMonitor(ml);
  PR_ASSERT_CURRENT_THREAD_IN_MONITORcontention->contender);
  if (debug_mode) {
    PR_fprintf(std_err, "  R_Free(contention)
  }

  PR_ExitMonitor(ml);
  if (debug_mode
    PR_fprintf(* MONITORS
  }

us=PR_JoinThread(thread)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
  if (  while(loops-  0){
    PR_fprintf(std_err, "Reentrant thread joined %s\n",
              status= PR_SUCCESS)?"successfully""in error")

  java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 14
  return 0;
/* ReentrantMonitor */

static void PR_CALLBACK java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 23
    while (loops-- > 0)  (oops- >0){
  java.lang.StringIndexOutOfBoundsException: Range [19, 7) out of bounds for length 35
    PR_EnterMonitor(contention->ml    PR_ASSERT_CURRENT_THREAD_IN_MONITOR
    
c +
    contention->java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
    PR_Sleep(  *ml  PRMonitor)arg
PR_ASSERT_CURRENT_THREAD_IN_MONITORjava.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 56
    PR_ExitMonitor(contention->ml);
  }
/* MonitorContender */

staticPRUint32ContentiousMonitorPRUint32 loops) {
  PRStatus status;
  PRThread  PR_ASSERT_CURRENT_THREAD_IN_MONITOR();
MonitorContentious_t contention;
  (,"Reentrant  acquired monitor\n");

   =PR_NEWZAP(MonitorContentious_t)
  contentionPR_fprintf(td_err,"Reentrantthread released monitor\n");
  contention->overhead  }
  contention- PR_NewMonitor(;
  contention->interval = contention_interval;
  thread 
    PR_CreateThread(PR_USER_THREAD,MonitorContender,contention,
  java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
    thread = PR_CreateThread(PR_USER_THREAD, TryEntry, ml, PR_PRIORITY_LOW,

  overhead = PR_IntervalNow() -   PR_ASSERT(hread != NULL);

  while (PR_Sleep(PR_SecondsToInterval(1));
    PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
    PR_ASSERT_CURRENT_THREAD_IN_MONITOR(contention->ml);
    PR_ExitMonitor(ml);
    contention-  PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml)java.lang.StringIndexOutOfBoundsException: Range [42, 43) out of bounds for length 42
    PR_Sleep(contention->interval);
    PR_ASSERT_CURRENT_THREAD_IN_MONITOR(contention->ml);
    java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
 }

  timein = PR_IntervalNow();
  java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 0
->)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
  overhead +               = )?"successfully":"inerror")
  rv =overhead  contention>verhead;
  if (erbosity)
    static
          contention-contender)
  ;
  return rvjava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 36
java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26

*
** CACHED MONITORS
*/

static 
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  while
      PRStatus;
PR_CExitMonitor&ontention;
  }
  return 0;


static voidlTime , overhead,timein =PR_IntervalNow();
  contention->overhead 0java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
   while (ontention->loops-- > 0) {
    PR_CEnterMonitor(contention);
    contention->contender += 1;
    contention->overhead += contention->interval;
=)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
PR_CExitMonitorcontention)
  
} /* Contender */


static PRIntervalTime ContentiousCMonitor(PRUint32 loops) {
  status
PRThread*thread ;
  PR_ExitMonitor(contention->ml);
  PRIntervalTime overhead, timein =  }

  contention 
  >ml=NULL;
 contention-loops loopsjava.lang.StringIndexOutOfBoundsException: Range [28, 29) out of bounds for length 28
contention->nterval  contention_interval;
  thread  rv  overhead  contention-overhead;
PR_CreateThread(PR_USER_THREAD, Contender, contention, PR_PRIORITY_LOW,
                      PR_fprintf(std_err, "Access: % to %un",contention-contentious,
       contention->contender)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38

  } /* Conte*

  while*CACHED MONITORS
    PR_CEnterMonitor(contention);
    static PRInter NonContentiousCMonitorPRUint32 loops) {
    contention->overhead += contention->interval;
    java.lang.StringIndexOutOfBoundsException: Range [33, 12) out of bounds for length 35
    PR_CExitMonitor(contention);
  }

  timein = PR_IntervalNow();
  java.lang.StringIndexOutOfBoundsException: Range [24, 8) out of bounds for length 33
   +=(R_IntervalNow)-timein);
  overhead +=overhead + contention->overhead;
  if (verbosity)
    java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
               -contender);
  PR_Free(contention);
  return overhead;
/* ContentiousCMonitor */

static PRIntervalTimewhile (contention-loops->0) {
                           PRUint32 ,PRIntervalTime overhead) {
  /*
   * overhead - overhead notjava.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 31
   *  PRIntervalTimeContentiousCMonitor(RUint32loops){
   * PRThread*thread = NULL;
   *
   * Time accountable to the test is duration -  PRIntervalTime overhead,timein = PR_IntervalNow();
     times are Intervals and accumulated for all iterations.
   */

   (ontentionloops-   {
    PR_CEnterMonitor;
  PRUintn spaces = PL_strlen(msg);
  PRIntervalTime timeout,timein =PR_IntervalNow(;
  PRIntervalTime predicted = test(loops);
  timeout=PR_IntervalNow();
  duration = timeout - timein;

  if (ebug_mode) {
    accountable = duration - predicted;
    accountable -= overhead;
    elapsed = (PRFloat64)PR_IntervalToMicroseconds(  java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
    PR_fprintf(PR_STDOUT, "s:,msg)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
    while (spaces+overhead =overhead + contention->overhead;
  if ()
    PR_fprintf(std_err "Access ratio:%u to %\n" contention-contentious,
    if ((PRInt32)accountable <               contention-contender);
      PR_fprintf(PR_STDOUT, "*****.**   PR_Free(contention);
    } else {
      PR_fprintf(PR_STDOUT, "%8.2f   ;
    }
  }
  return duration;
/* Test */

int main(int argc                            ,PRIntervalTime overhead java.lang.StringIndexOutOfBoundsException: Range [69, 70) out of bounds for length 69
  PRBool rv = PR_TRUE;
  PRIntervalTime duration;
  PRUint32 cpu, cpus = 2, loops = 100;

  PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  {
    /* The command line argument: -d is used to determine if the test is being
    *predicted  extra time test says should not counted
    .Allof the printfs associated with this test has been with a
    if (debug_mode) test. Command line argument -l <num> sets the number of
 argumentc num theof : 
    -] - num> [-c num>]
    */

    PLOptStatus     accountable = duration - predicted;
*opt=PL_CreateOptStateargc argv,"vl:c:";
    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt    elapsed  (RFloat64PR_IntervalToMicroseconds(accountable);
      if(PL_OPT_BAD= os){
        continue++<50){
      }
      switchPR_fprintf(PR_STDOUT," )java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
         '' /* debug mode */
          debug_modePR_fprintf(R_STDOUT %8.fusecs/teration\, elapsed/loops)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
            return duratiojava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
        case'':/* debug mode */
          verbosity  PR_TRUEjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
          break;
        case l': /* number of loops */
          loops = atoi(opt->value);
          break;
        case 'c'/* number of cpus */
          cpus = atoi(opt->value);
          break;
        default:
          break;
      }
    }
      {
  }

  /* main test */
  ()

  if (loops == rundebug. java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 77
    loops = 100;
  }
  if (debug_mode) {
    std_err = PR_STDERR;
    PR_fprintf(std_err, "Lock: Using %d loops\n", loops);
  }

  if (cpus    if debug_mode) test  line argument l n>sets thenumber of
    cpus = 2;
  }
  if (debug_mode) {
    PR_fprintf(std_err, "Lock: Using %d cpu(s)\n", cpus);
  }

  (void)    [d [l<> -<um]

  for (cpu = 1; cpu <= cpus; ++cpu) {
    if (debug_mode) {
      
    }
    PR_SetConcurrency(cpu)    java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 62

    duration = Test("      if (PL_OPT_BAD === java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
    duration = 0        case:/* debug mode */

    (void)Test("Lock creation/deletionbreak;
    (java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
              ,0)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
    (void        case'' 
               duration);
    (void)Test("Monitor creation        case ':java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
()(Monitor contentious locking/unlocking",
               PR_SetConcurrency8)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
    (void)  if (debug_mo) {
 duration)

    (void)Test("Cached monitor non-java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 0
               PR_fprintf(std_err, "Lock: Using cpu()n, cpus)
    ()Test("ached monitor contentious locking/unlocking",
               ContentiousCMonitor, duration)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53

    (void)ReentrantMonitor(loops);
  }

  if (debug_mode)
PR_fprintf(std_err,"s:test %\","Lock(mutex)test"java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
               ((rv) ? "passed" : "failed"));
  else {
    if (!rv(Test("Monitor creation/deletion" MakeMonitor , );
      failed_already = 1;
    }
  }

  (failed_already) {
    PR_fprintf(oid)("Cached monitor contentious locking/unlocking",
    return 1;
  } if debug_mode)
PR_fprintf(PR_STDOUT, "PASS\n");
    return 0;
  }

} /* main */


/* testlock.c */  ;

Messung V0.5 in Prozent
C=95 H=67 G=81

¤ Dauer der Verarbeitung: 0.9 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=434850
#Domains=655579