Skip to content
Snippets Groups Projects
Commit bc8592eb authored by rswindell's avatar rswindell
Browse files

Added sleep_test_thread, verifies that SLEEP doesn't put parent to sleep.

Renamed thread_test to sem_test_thread.
parent 987865cf
Branches
Tags
No related merge requests found
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
#include "threadwrap.h" #include "threadwrap.h"
static void getkey(void); static void getkey(void);
static void thread_test(void* arg); static void sem_test_thread(void* arg);
static void sleep_test_thread(void* arg);
typedef struct { typedef struct {
sem_t parent_sem; sem_t parent_sem;
...@@ -75,6 +76,25 @@ int main() ...@@ -75,6 +76,25 @@ int main()
SLEEP(5000); SLEEP(5000);
printf("slept %ld seconds\n",time(NULL)-t); printf("slept %ld seconds\n",time(NULL)-t);
/* Thread SLEEP test */
printf("\nThread SLEEP(5 second) test\n");
getkey();
i=0;
if(_beginthread(
sleep_test_thread /* entry point */
,0 /* stack size (0=auto) */
,&i /* data */
)==(unsigned long)-1)
printf("_beginthread failed\n");
else {
SLEEP(1); /* yield to child thread */
while(i==0) {
printf(".");
fflush(stdout);
SLEEP(1000);
}
}
/* glob test */ /* glob test */
printf("\nglob(%s) test\n",glob_pattern); printf("\nglob(%s) test\n",glob_pattern);
getkey(); getkey();
...@@ -106,7 +126,7 @@ int main() ...@@ -106,7 +126,7 @@ int main()
printf("\nFree disk space: %lu bytes\n",getfreediskspace(path)); printf("\nFree disk space: %lu bytes\n",getfreediskspace(path));
/* Thread (and inter-process communication) test */ /* Thread (and inter-process communication) test */
printf("\nThread test\n"); printf("\nSemaphore test\n");
getkey(); getkey();
sem_init(&thread_data.parent_sem sem_init(&thread_data.parent_sem
,0 /* shared between processes */ ,0 /* shared between processes */
...@@ -117,9 +137,9 @@ int main() ...@@ -117,9 +137,9 @@ int main()
,0 /* initial count */ ,0 /* initial count */
); );
if(_beginthread( if(_beginthread(
thread_test /* entry point */ sem_test_thread /* entry point */
,0 /* stack size (0=auto) */ ,0 /* stack size (0=auto) */
,&thread_data /* data */ ,&thread_data /* data */
)==(unsigned long)-1) )==(unsigned long)-1)
printf("_beginthread failed\n"); printf("_beginthread failed\n");
else { else {
...@@ -145,13 +165,24 @@ static void getkey(void) ...@@ -145,13 +165,24 @@ static void getkey(void)
fflush(stdout); fflush(stdout);
} }
static void thread_test(void* arg) static void sleep_test_thread(void* arg)
{
time_t t=time(NULL);
printf("child sleeping");
fflush(stdout);
SLEEP(5000);
printf("\nchild awake after %ld seconds\n",time(NULL)-t);
*(int*)arg=1; /* signal parent: we're done */
}
static void sem_test_thread(void* arg)
{ {
ulong i; ulong i;
thread_data_t* data = (thread_data_t*)arg; thread_data_t* data = (thread_data_t*)arg;
printf("thread_test entry\n"); printf("sem_test_thread entry\n");
sem_post(&data->child_sem); sem_post(&data->child_sem); /* signal parent: we've started */
for(i=0;i<10;i++) { for(i=0;i<10;i++) {
sem_wait(&data->parent_sem); sem_wait(&data->parent_sem);
...@@ -159,6 +190,6 @@ static void thread_test(void* arg) ...@@ -159,6 +190,6 @@ static void thread_test(void* arg)
sem_post(&data->child_sem); sem_post(&data->child_sem);
} }
printf("thread_test exit\n"); printf("sem_test_thread exit\n");
sem_post(&data->child_sem); sem_post(&data->child_sem); /* signal parent: we're done */
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment