mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: naresh kamboju <naresh.kernel@gmail.com>
To: ltp-list <ltp-list@lists.sourceforge.net>
Cc: Subrata Modak <subrata@linux.vnet.ibm.com>,
	Garrett Cooper <yanegomi@gmail.com>,
	Masatake YAMATO <yamato@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] Synchronization required before release the lock:  sem_post/8-1.c
Date: Thu, 25 Feb 2010 19:15:42 +0530	[thread overview]
Message-ID: <f5a7b3811002250545x3d5288cfqd114d3bcd79581f2@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2836 bytes --]

Hi,

I have found abnormal behavior of sem_post/8-1.c test case under posix.
This test case passes in some times and failed in many times :-(

After my investigation found synchronization is missing between the
child processes.
Made a patch to fix this issue.

Patch includes
1.	Reverting back changes made by mreed on Sep 25 2006. Making sure
child has been waiting for the lock (below Refs).
2.	using sleep in while loop is not a good idea, so sleep is removed
from while loop
3.	For the synchronization I have added sleep before releasing the lock.


After applying this patch I have tested this test case 1000 times continuously.
All the times test case reported as Test Pass :-)


Signed-off-by: Naresh Kamboju < naresh.kernel@gmail.com >
---
 testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c
|   15    8 +     7 -     0 !
 1 file changed, 8 insertions(+), 7 deletions(-)

Index: b/testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c
===================================================================
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c
@@ -161,7 +161,6 @@ int main()
        }
        fprintf(stderr, "P: child_1:%d forked\n", c_1);

-       sleep(1);
        c_2 = fork();
        if (c_2 == 0)
        {
@@ -176,13 +175,13 @@ int main()
        }
        fprintf(stderr, "P: child_2: %d forked\n", c_2);

+        /* Step 3 Implementation */
        /* Make sure the two children has been waiting */
-       /*do {
-               sleep(1);
+       do {
                sem_getvalue(sem_1, &val);
                //printf("val = %d\n", val);
        } while (val != 1);
-       */
+
        c_3 = fork();
        if (c_3 == 0)
        {
@@ -191,13 +190,15 @@ int main()
        }
        fprintf(stderr, "P: child_3: %d forked\n", c_3);

+        /* Step 3 Implementation */
        /* Make sure child 3 has been waiting for the lock */
-       /*do {
-               sleep(1);
+       do {
                sem_getvalue(sem_1, &val);
                //printf("val = %d\n", val);
        } while (val != 0);
-       */
+
+       /* Synchronization required before release the lock */
+       sleep(1);
        /* Ok, let's release the lock */
        fprintf(stderr, "P: release lock\n");
        sem_post(sem);


Test script to test 1000 times:
/*****************************************************/
#!/bin/sh

for ((  i = 0 ;  i < 1000;  i++  ))

do

./8-1.test >> /tmp/sem-post-8-1.log
done
/*****************************************************/

Refs:
http://ltp.cvs.sourceforge.net/viewvc/ltp/ltp/testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c?view=log

Please review this patch and let me know if you have any issues.

Best regards
Naresh Kamboju

[-- Attachment #2: posix-sem-post-unstable-fix.patch --]
[-- Type: application/octet-stream, Size: 1383 bytes --]

---
 testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c |   15 	8 +	7 -	0 !
 1 file changed, 8 insertions(+), 7 deletions(-)

Index: b/testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c
===================================================================
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_post/8-1.c
@@ -161,7 +161,6 @@ int main() 
 	}
 	fprintf(stderr, "P: child_1:%d forked\n", c_1);
 	
-	sleep(1);
 	c_2 = fork();
 	if (c_2 == 0)
 	{
@@ -176,13 +175,13 @@ int main() 
 	}
 	fprintf(stderr, "P: child_2: %d forked\n", c_2);
 
+        /* Step 3 Implementation */
 	/* Make sure the two children has been waiting */	
-	/*do { 
-		sleep(1);
+	do {
 		sem_getvalue(sem_1, &val);
 		//printf("val = %d\n", val);
 	} while (val != 1);
-	*/
+
 	c_3 = fork();
 	if (c_3 == 0)
 	{
@@ -191,13 +190,15 @@ int main() 
 	}
 	fprintf(stderr, "P: child_3: %d forked\n", c_3);
 	
+        /* Step 3 Implementation */
 	/* Make sure child 3 has been waiting for the lock */	
-	/*do { 
-		sleep(1);
+	do {
 		sem_getvalue(sem_1, &val);
 		//printf("val = %d\n", val);
 	} while (val != 0);
-	*/
+
+	/* Synchronization required before release the lock */
+	sleep(1);
 	/* Ok, let's release the lock */
 	fprintf(stderr, "P: release lock\n");
 	sem_post(sem);

             reply	other threads:[~2010-02-25 13:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-25 13:45 naresh kamboju [this message]
2010-03-02  8:50 ` [LTP] " Rishikesh K Rajak
2010-03-02 15:08   ` naresh kamboju
     [not found]     ` <20100303045624.GB10185@linux.vnet.ibm.com>
2010-03-03  6:00       ` naresh kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f5a7b3811002250545x3d5288cfqd114d3bcd79581f2@mail.gmail.com \
    --to=naresh.kernel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=subrata@linux.vnet.ibm.com \
    --cc=yamato@redhat.com \
    --cc=yanegomi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®