To find a conccurent bug, both buggy input and buggy schedule are required. However in a normal execution, we can specify input but we cannot specify the schedule. Thus it is hard to find a conccurrent bug with a normal execution and we need a tool to explore schedules.
In projects 2 and 3, you will implement a simplified version of CHESS to explore schedules systematically.
In project 2, you will implement a deterministic scheduler. That allows only one thread to execute at one time and repeated executions with the same input produce the same sequence of instructions. Your deterministic scheduler will be tested with 2-thread concurrent programs.
Enter a thread | LOCK(GL) |
---|
Leave a thread | UNLOCK(GL) |
---|
pthread_mutex_lock | if (L is held by other threads) UNLOCK(GL); /* select next available thread to execute */ /* wait till L is not held by any other threads */ LOCK(GL); LOCK(L); else LOCK(L); |
---|
pthread_join | UNLOCK(GL); /* select next available thread to execute */ /* wait till joinee terminates */ LOCK(GL); |
---|
sched_yield | UNLOCK(GL); /* select next available thread to execute */ LOCK(GL); |
---|
You will implement these primitives by using the provided template. The implementation will be compiled to a dynamic library in place of the standard pthread library. When it is linked and executed with a concurrent program, deterministic execution can be achieved. Note that you should not need to change anything in the test programs.
You can use the following template for the basic part of the tool. The template has a basic implementation to wrap pthread functions. Your code should be compiled in the unix or linux machine.
Use the makefile included in the package. Type 'make' in the directory with makefile and source code and chess.so will be built.
Use run.sh in the package. Type './run.sh ./sample' in the directory with chess.so and run.sh will execute program sample in the current directory with the tool.
This program will print out numbers with two threads and the order of numbers will change as schedules. The deterministic scheduler should produce same input at every execution.
You can build sample1.c by typing 'gcc -o sample1 -lpthread -lrt sample1.c' on the shell.
Post your questions through Piazza, the instructor and his PhD student(s) will answer your questions as quick as possible.
You can find a document about pthread from internet including pthread tutorial from Lawrence Livermore National Laboratory