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

35
LINES

< > BotCompany Repo | #1035565 // FastCollabWorker - uses spin-locking or ms sleep

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9670L/53K).

srecord noeq FastCollabWorker(FastCollab collab, int workerIndex) extends Thread {
  volatile gettable long errorCount;
  volatile gettable long spinWaits;
  volatile gettable long workCount;
  volatile gettable Throwable lastError;
  settable PingSource interruptor;
  int sleepTime;
  
  run {
    Runnable work;
    var interruptor = this.interruptor;
    sleepTime = collab.sleepTime;
    
    while ((work = collab.grabWork(workerIndex)) != collab.DONE) {
      interruptor?.ping();
      try {
        if (work != null) {
          ++workCount;
          work.run();
        } else
          waitSome();
      } catch e {
        ++errorCount;
        lastError = e;
      }
    }
  }
  
  void waitSome ctex {
    if (sleepTime == 0)
      ++spinWaits;
    else
      sleep(sleepTime);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035565
Snippet name: FastCollabWorker - uses spin-locking or ms sleep
Eternal ID of this version: #1035565/8
Text MD5: c13704fa386012993e966d71f658f677
Transpilation MD5: 84c925100f53966a9c61c4947d414b08
Author: stefan
Category: javax / parallelism
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-03 19:53:17
Source code size: 832 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 169 / 251
Version history: 7 change(s)
Referenced in: [show references]