summaryrefslogtreecommitdiff
path: root/apps/examples/ostest/waitpid.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-26 00:56:59 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-26 00:56:59 +0000
commit16b331cdc8d014264d17099f7034e45fca0bd7a8 (patch)
tree7cf6ab24b9e0d8c17f3df339eb82c1c74dcfd736 /apps/examples/ostest/waitpid.c
parent2839e79985e189fdbe5f1ab1d7229369aa70072b (diff)
downloadnuttx-16b331cdc8d014264d17099f7034e45fca0bd7a8.tar.gz
nuttx-16b331cdc8d014264d17099f7034e45fca0bd7a8.tar.bz2
nuttx-16b331cdc8d014264d17099f7034e45fca0bd7a8.zip
Minor changes to make OS test more robust in the presence of many memory allocation failures
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5672 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples/ostest/waitpid.c')
-rw-r--r--apps/examples/ostest/waitpid.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/apps/examples/ostest/waitpid.c b/apps/examples/ostest/waitpid.c
index 67cd81fdc..0649748a2 100644
--- a/apps/examples/ostest/waitpid.c
+++ b/apps/examples/ostest/waitpid.c
@@ -87,7 +87,7 @@ static void waitpid_start_children(void)
ret = TASK_CREATE("waitpid", PRIORITY, STACKSIZE, waitpid_main, NULL);
if (ret < 0)
{
- printf("waitpid_start_child: ERROR Failed to start user_main\n");
+ printf("waitpid_start_child: ERROR Failed to start waitpid_main\n");
}
else
{
@@ -100,8 +100,29 @@ static void waitpid_start_children(void)
static void waitpid_last(void)
{
+ pid_t pid = -1;
int stat_loc;
int ret;
+ int i;
+
+ /* Find the last child thread that was started successfully */
+
+ for (i = NCHILDREN-1; i > 0; i--)
+ {
+ if (g_waitpids[i] >= 0)
+ {
+ pid = i;
+ break;
+ }
+ }
+
+ /* Is there any thread to wait for? */
+
+ if (pid < 0)
+ {
+ printf("waitpid_last: ERROR: Nothing to wait for\n");
+ return;
+ }
printf("waitpid_last: Waiting for PID=%d with waitpid()\n",
g_waitpids[NCHILDREN-1]);
@@ -196,7 +217,7 @@ int waitpid_test(void)
g_waitpids[0], stat_loc);
}
- /* Wait a big to make sure that the other threads complete */
+ /* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);
@@ -246,7 +267,7 @@ int waitpid_test(void)
info.si_pid, info.si_status);
}
- /* Wait a big to make sure that the other threads complete */
+ /* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);
@@ -289,7 +310,7 @@ int waitpid_test(void)
info.si_pid, info.si_status);
}
- /* Wait a big to make sure that the other threads complete */
+ /* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);
@@ -332,7 +353,7 @@ int waitpid_test(void)
ret, stat_loc);
}
- /* Wait a big to make sure that the other threads complete */
+ /* Wait a bit to make sure that the other threads complete */
waitpid_last();
sleep(1);