Deadlock Free Code

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Thus, the do_work function could never complete. This is a deadlock situation.

The simple way to fix the problem in the previous code is to do the inlining of the dequeue function in the do_work function as follows: Deadlock free code:
void do_work(NODE *node) { #pragma omp critical (x) { node->next->data = n!(node->data)" node = node->next" # #

It is sometimes you may require that a statement in a high level language complete in its entirety before a thread is suspended. !or example, a statement x"" is translated into a sequence of machine instructions such as: load reg, [x]; add reg 1; store [x], reg; It is possible that the thread is swapped out between two of these machine instructions. The atomic pragma directs the compiler to generate code toensure that the specific memory storage is updated atomically. The following code example shows a usage of the atomic pragma. int main#$ % float y&'((()* int k, idx&'((()* +pragma omp parallel for shared#y, idx$ for # k , (* k - .(((* k""$ % idx&k) , k / '(((* y&idx&k)) , ..(* 0 +pragma omp parallel for shared#y, idx$ for # k , (* k - .(((* k""$ % +pragma omp atomic y&idx&k)) ", ..( 1 #k / '((($* 0 return (* 0 2n expression statement that is allowed to use the atomic pragma must be with one of the following forms: x binop , exp x"" ""x x3 x

Department CSE, SCAD CET

In the preeding expressions, x is an lvalue expression with scalar type* expr is an expression with scalar type and does not reference the ob4ect designed by x* binop is not an overloaded operator and is one of ", 1, , 5, 6, 7 , 8 , --, or 99 for the :5:"" language. Factors Affecting Performance of OpenMp Program: ;pen <p provides a simple and portable way for paralleli=e the applications to develop threaded applications. Threaded application performance with ;pen <p is largely dependent on the following program. The >nderlying performance of single threaded core. The percentage of program #i.e$run in parallel 6 its scalability. :?> utili=ation datalocality#availability of data$ 6 load balancing.#each thread

Department CSE, SCAD CET

You might also like