Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1016805 // Provoke DeadLock (& have OS solve it) [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (14693L/101K).

!7

sclass ProvokeDeadLock > DynPrintLog {
  transient Lock a = fairLock();
  transient Lock b = fairLock();

  JComponent visualize() {
    ret withCenteredButtons(super.visualize(),
      "Do the deadlock", rThread doIt);
  }
  
  void doIt {
    temp dm_tempDisableAllButtons();
    
    print("Initiating deadlock... :-)\n");
    
    Thread threadA = startThread("A", r {
      lock a; // cool new syntax!
      print("Thread A has lock A.");
      sleep1Second();
      print("Thread A getting lock B.");
      lock b;
      print("Thread A successful!");
    });
    
    Thread threadB = startThread("B", r {
      lock b;
      print("Thread B has lock B.");
      sleep1Second();
      print("Thread B getting lock A.");
      lock a;
      print("Thread B successful!");
    });
    
    joinThreads(threadA, threadB);
    setModuleName(print("Deadlock solved!"));
  }
}

Author comment

Began life as a copy of #1009356

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1016805
Snippet name: Provoke DeadLock (& have OS solve it) [Dyn Module]
Eternal ID of this version: #1016805/9
Text MD5: 3e7c509cbae334e42ea95e7b3ce16d3b
Transpilation MD5: 3f302aacbac6a78fd6d39b4fee02f53c
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-03 00:12:02
Source code size: 918 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 605 / 759
Version history: 8 change(s)
Referenced in: