22.07.2013 Views

Download File

Download File

Download File

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

if (semop(semid, operations, 1) < 0)<br />

{<br />

perror("parent semop");<br />

exit(1);<br />

}<br />

*parent_shm = *parent_shm + 1;<br />

if (i%1500 == 0)<br />

{<br />

usleep(1); // sleep 1 us to increase window of critical section<br />

}<br />

operations[0].sem_num = 0;<br />

operations[0].sem_op = 1;<br />

operations[0].sem_flg = 0;<br />

if (semop(semid, operations, 1) < 0)<br />

{<br />

perror("parent semop");<br />

exit(1);<br />

}<br />

// wait for child to complete<br />

wait(&status);<br />

/*<br />

* now that parent and child are done incrementing, check the<br />

* consistency of the shm memory.<br />

*/<br />

printf("Child Incremented %d times, Parent %d times. SHM Value %d<br />

\n",CHILD_INCREMENT_COUNT,PARENT_INCREMENT_COUNT,<br />

*parent_shm);<br />

NP Lab Manual , RNEC page: 22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!