Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I make a thread join on another thread but only wait for n seconds of CPU time?
    primarykey
    data
    text
    <p><code>otherThread.join( time )</code> appears to wait <code>time</code> in real milliseconds. I want to wait <code>time</code> in actual CPU time so that I can get consistent behavior within my application. </p> <p>I've done a quick look at <code>ThreadMXBean</code> but that doesn't quite seem to have what I wanted ( it tells me the threads actual CPU time, but offers no convenient way to wait until some time has passed ) . A busy loop around a <code>sleep()</code> could work, but seems grossly inefficient. </p> <p>I also thought about using another thread and waiting on a <code>Condition</code>, but I'm not sure how that would work. The main thread would do: <code>myCondition.await()</code> , where another thread that would toggle <code>myCondition</code> when <code>otherThread</code> had used <code>time</code> actual CPU time. Again, this seems complicated and would probably still require the controlling thread to have a busy loop.</p> <p><strong>Edit:</strong> I'm doing this for a grading script. This means that I need to have a way to timeout if the student is in an infinite loop and it needs to be fair. I've been using JUnit to run tests on students, but that has the same problem with timing out: if the same (inefficient) submission is run multiple times, it could possibly get different grades depending on what other jobs are running on the machine at the time (a real problem for group work). </p> <p>But this is a problem with <em>normal</em> unit testing, too - by using clock time instead of CPU time JUnit gets inconsistent test results?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload