Locks with multiple threads parallel programming in C++
<p>How to answer this? please help.</p>

<p>Consider the following program with 3 threads.</p>

<pre><code>locks l1, l2, l3;
</code></pre>

<p>*Thread 1</p>

<pre><code>while(1){

l1.lock();

l2.lock();

printf(“Red”);

l3.unlock();

l1.unlock();}
</code></pre>

<p>*Thread 2</p>

<pre><code>while(1){

l2.lock();

l3.lock();

printf(“Green”);

l1.unlock();

l2.unlock();}
</code></pre>

<p>*Thread 3</p>

<pre><code>while(1){

l3.lock();

l1.lock();

printf(“Blue”);

l2.unlock();

l3.unlock();}
</code></pre>

<p>a) What are the possible outcomes of the above program. Can you explain how this'll happen?
b) Will this code lead to a deadlock?</p>