-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-threading: checking that the student use multiple threads #41
Comments
It seems that it is doable in a reasonable way. I did a POC here
The idea is the following:
In java code, it looks like that @Test
public void testNumberThreads() {
HashSet<Thread> threadsSeen = new HashSet<>();
int [] threadLaunchedByStudentCode = new int[]{0};
Thread t = new Thread(new Runnable(){
public void run() {
while (true) {
for (Thread th : Thread.getAllStackTraces().keySet()) {
if (!threadsSeen.contains(th)) {
threadLaunchedByStudentCode[0] += 1;
threadsSeen.add(th);
}
}
}
}
});
t.setDaemon(true);
t.start();
for (Thread th : Thread.getAllStackTraces().keySet())
threadsSeen.add(th);
int nThreads = 4;
StudentCode.run(..., nThreads);
Assert.assertEquals(nThreads, threadLaunchedByStudentCode[0]);
} /!\ this method to test is not stable with respect to thread executions (some threads might be forgotten) /! A more durable way of doing things might be to add bytecode the the |
Related to this type of questions (I need to log this so we do not forget it). When doing the exam we ran into a problem with an exercise on threads: the Inginious task timed out (the container) with time out for the tasks set to 1 second. This should obviously never happen. Below is the minimal code to reproduce the error. The code of the student to be evaluated: import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
public class Code {
public static void main(String [] args) {
ExecutorService service = Executors.newFixedThreadPool(10);
service.submit(() -> {});
//service.shutdown();
}
} Notice how the Thus when the A quick fix would be to do a Another idea, more scalable, is to shutdown ourselve the service using reflection. We just need to add a check to do that at the end of every test and update a flag is the service is not shutdown. Then we can add a test to test the value of the flag. |
In module 6, we introduce the students to multi-threading programming.
In the exercises, it is diffcult to actually test if they use or not multiple threads. And even if they use multiple threads, are they doing what they should be doing?
It seems that we can access the runtime stack trace of the threads using this method.
We should investigate how this can be translated in the exercise.
The text was updated successfully, but these errors were encountered: