Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
bc8592eb
Commit
bc8592eb
authored
23 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Added sleep_test_thread, verifies that SLEEP doesn't put parent to sleep.
Renamed thread_test to sem_test_thread.
parent
987865cf
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/wraptest.c
+41
-10
41 additions, 10 deletions
src/xpdev/wraptest.c
with
41 additions
and
10 deletions
src/xpdev/wraptest.c
+
41
−
10
View file @
bc8592eb
...
@@ -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
(
"
\n
Thread 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
(
"
\n
glob(%s) test
\n
"
,
glob_pattern
);
printf
(
"
\n
glob(%s) test
\n
"
,
glob_pattern
);
getkey
();
getkey
();
...
@@ -106,7 +126,7 @@ int main()
...
@@ -106,7 +126,7 @@ int main()
printf
(
"
\n
Free disk space: %lu bytes
\n
"
,
getfreediskspace
(
path
));
printf
(
"
\n
Free disk space: %lu bytes
\n
"
,
getfreediskspace
(
path
));
/* Thread (and inter-process communication) test */
/* Thread (and inter-process communication) test */
printf
(
"
\n
Thread
test
\n
"
);
printf
(
"
\n
Semaphore
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
(
"
\n
child 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 */
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment