On 3/23/2012 12:21 PM, Hamid Reza Khaleghzadeh wrote:
> Hi Dear Eliot,

I added valgrind-users back so that all can follow the email thread.

> Thanks for your answer. You said that "Valgrind does support multiple 
> threads, but runs only one
> thread at a time."
> Suppose a two threaded application. The threads run in parallel. Suppose 
> thread1 read A, thread2
> simultaneously write A, and thread1 read A again. In this case, records of 
> output trace are as
> following (holds order of access) ?
> Thread1 read A
> Thread2 write A
> Thread1 read A

It depends on whether the scheduler swaps threads at the two places indicated.
Perhaps it will help to think of the trace as being what you might get from
running your multi-thread program on a single cpu, where the operating system
periodically switches between runnable threads.  In fact, valgrind will try
to switch when the underlying OS does.  However, for various reasons valgrind
tends to emulate the execution of whole sequences of instructions in one go,
and such thread switching will not happen in the middle of a sequence.  Thus
if Thread1 reads A twice in the *same* such sequence, you will never see
Thread2 do anything between the two reads.

You may be able to control with your instrumentation where the sequences end,
but performance will be very bad if you end them at every read and write. Also,
you still get each thread normally running for a full scheduler quantum before
a switch will be attempted.

In sum, you should get one *possible* execution, but it won't necessarily be
one typical of truly concurrent execution.  (Just because you have threads
that are *runnable* at the same time does not mean that they actually run
*concurrently* in a real system, unless you guarantee multuple cpus are
available. You can think of valgrind as providing a universe where only one
cpu is *ever* available.)

There are many good reasons why valgrind is this way; it would be
substantially more difficult to build (and maintain!) a similar tool that
supported true concurrency.

> Thanks for your answer in advance.

No problem.

Eliot Moss

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to