Presentation is loading. Please wait.

Presentation is loading. Please wait.

Debugging on Shared Memory Introduction to Valgrind Multithreads Tools & Principles 林孟潇 14302010043.

Similar presentations


Presentation on theme: "Debugging on Shared Memory Introduction to Valgrind Multithreads Tools & Principles 林孟潇 14302010043."— Presentation transcript:

1 Debugging on Shared Memory Introduction to Valgrind Multithreads Tools & Principles 林孟潇 14302010043

2 Shared Memory Parallel Programming ▪All processes/threads share a common address space. ▪Some of them may be running at the same time on different processors. ▪Has shown better efficiency in Web Server and some other fields.

3 Data Racing ▪One or more threads access the same memory location without sufficient locking. ▪If one subtask is reading a variable while the other is writing it, the result is unpredictable. ▪The safe way is to use a mutex or lock to protect the critical section.

4 Data Racing Thread 1 my_rank=1 racer=0

5 Data Racing Thread 1 my_rank=1 tmp=0 racer=0

6 Data Racing Thread 1 my_rank=1 tmp=0 racer=0 Thread 2 my_rank=2

7 Data Racing Thread 1 my_rank=1 tmp=0 racer=0 Thread 2 my_rank=2 tmp=0

8 Data Racing Thread 1 my_rank=1 tmp=0 racer=0 Thread 2 my_rank=2 tmp=0

9 Data Racing Thread 1 my_rank=1 tmp=0 racer=0 Thread 2 my_rank=2 tmp=0

10 Data Racing Thread 1 my_rank=1 tmp=0 racer=1 Thread 2 my_rank=2 tmp=0

11 Data Racing Thread 1 my_rank=1 tmp=0 racer=1 Thread 2 my_rank=2 tmp=0

12 Data Racing Thread 1 my_rank=1 tmp=0 racer=1 Thread 2 my_rank=2 tmp=0

13 Data Racing Thread 1 my_rank=1 tmp=0 racer=1 Thread 2 my_rank=2 tmp=0

14 Valgrind Helgrind ▪Helgrind is a thread debugger which finds data races in multithreaded programs. ▪It looks for memory locations which are accessed by more than one thread, but for which no consistently used lock can be found. ▪Working with POSIX pthreads.

15 Valgrind DRD ▪The tool works for any program that uses the POSIX threading primitives or that uses threading concepts built on top of the POSIX threading primitives. ▪For most programs DRD needs less memory to perform its analysis. ▪DRD has support for detached threads. ▪Newer than Helgrind

16 Happens-before Relation Parent ThreadChild Thread int var; pthread_create(…) var=20var=10 exit pthread_join(…) printf("%d\n", var); Which instruction will be executed first?

17 Happens-before Relation Parent ThreadChild Thread int var; pthread_create(…) var=20 send message to childwait message var=10 exit pthread_join(…) printf("%d\n", var); Now the order is clear!

18 Happens-before Relation

19 Run Valgrind Tools ▪valgrind --tool=drd ▪valgrind --tool=helgrind

20 Q&A


Download ppt "Debugging on Shared Memory Introduction to Valgrind Multithreads Tools & Principles 林孟潇 14302010043."

Similar presentations


Ads by Google