Android Open Source - androidtestdebug Dekker






From Project

Back to project page androidtestdebug.

License

The source code is released under:

MIT License

If you think the Android project androidtestdebug listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

public class Dekker {  
    private static volatile int _flag1 = 0;
  private static volatile int _flag2 = 0;
  private static volatile int _turn = 1;
  private static volatile int _sharedCounter = 0;
//from w  w  w.j  ava 2  s  . c  om
    private static void dekker1() {
      _flag1 = 1;
    _turn = 2;
    while ((_flag2 == 1) && (_turn == 2));
    _sharedCounter++;
    _flag1 = 0;
  }

  private static void dekker2() {
      _flag2 = 1;
    _turn = 1;
    while ((_flag1 == 1) && (_turn == 1));
    _sharedCounter++;
    _flag2 = 0;
  }
  
  public static void main(String[] args) throws Exception {
      if ( args.length != 1 ) {
         System.out.println("????: java Dekker <????>");
       return;
    }

    final int loopCount = Integer.parseInt(args[0]);
    Thread thread1 = new Thread(new Runnable() {
        public void run() {
        for ( int i = 0; i < loopCount; ++i ) {
          dekker1();
        }
      }
    });
    Thread thread2 = new Thread(new Runnable() {
        public void run() {
        for ( int i = 0; i < loopCount; ++i ) {
          dekker2();
        }
      }
    });
    thread1.start();
    thread2.start();

    thread1.join();
    thread2.join();

    int expected_sum = 2 * loopCount;
    if ( _sharedCounter != expected_sum ) {
         System.out.println(
           String.format("???????: ???? $1%d ???????? $2%d", _sharedCounter, expected_sum));
    } else { 
                     System.out.println("Dekker?????????");
                }
  }
}




Java Source Code List

.????2.java
.ClbDemoClass.java
.DataDrivenDemoTest.java
.DeadLockDemo.java
.Dekker.java
.FirstDemo.java
.FirstDemo.java
.MemoryLog.java
.RaceConditionFix.java
.RaceCondition.java
.Sample1Test.java
.Sample1.java
.Sample2Test.java
.Sample2.java
.SampleSuite.java
bpdemo.BpDemo.java
bpdemo.ClbDemoClass.java
.bpdemo.java
cc.iqa.iquery.mr.By.java
cc.iqa.iquery.mr.ControlHierarchy.java
cc.iqa.iquery.mr.Plugin.java
cc.iqa.iquery.mr.QueryableDevice.java
chapter11.HelloWorld.java
com.android.example.spinner.SpinnerActivity.java
com.example.android.hcgallery.CameraFragment.java
com.example.android.hcgallery.CameraFragment.java
com.example.android.hcgallery.CameraFragment.java
com.example.android.hcgallery.CameraSample.java
com.example.android.hcgallery.CameraSample.java
com.example.android.hcgallery.CameraSample.java
com.example.android.hcgallery.ContentFragment.java
com.example.android.hcgallery.ContentFragment.java
com.example.android.hcgallery.ContentFragment.java
com.example.android.hcgallery.DirectoryCategory.java
com.example.android.hcgallery.DirectoryCategory.java
com.example.android.hcgallery.DirectoryCategory.java
com.example.android.hcgallery.DirectoryEntry.java
com.example.android.hcgallery.DirectoryEntry.java
com.example.android.hcgallery.DirectoryEntry.java
com.example.android.hcgallery.Directory.java
com.example.android.hcgallery.Directory.java
com.example.android.hcgallery.Directory.java
com.example.android.hcgallery.FitCenterFrameLayout.java
com.example.android.hcgallery.FitCenterFrameLayout.java
com.example.android.hcgallery.FitCenterFrameLayout.java
com.example.android.hcgallery.INotifyDirectoryChanged.java
com.example.android.hcgallery.INotifyDirectoryChanged.java
com.example.android.hcgallery.INotifyDirectoryChanged.java
com.example.android.hcgallery.MainActivity.java
com.example.android.hcgallery.MainActivity.java
com.example.android.hcgallery.MainActivity.java
com.example.android.hcgallery.TitlesFragment.java
com.example.android.hcgallery.TitlesFragment.java
com.example.android.hcgallery.TitlesFragment.java
com.example.tests.FirstDemo.java
.gcdemo.java
.gcdemo.java
.????.java
.???????????.java
temp.CaseErrorException.java
temp.Constants.java
temp.Login2blogTest.java
temp.UserOperationsHelper.java