Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
61825fd6
Commit
61825fd6
authored
Nov 18, 2010
by
Sander van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Continued assignment 4 of Operating Systems.
parent
834a9bcd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
17 deletions
+42
-17
os/.gitignore
os/.gitignore
+1
-0
os/ass4/Makefile
os/ass4/Makefile
+7
-1
os/ass4/ass4
os/ass4/ass4
+0
-0
os/ass4/main.c
os/ass4/main.c
+33
-15
paper/paper.tex
paper/paper.tex
+1
-1
No files found.
os/.gitignore
View file @
61825fd6
ass*/ass*
*.o
*.o
os/ass4/Makefile
View file @
61825fd6
PROG
=
ass4
PROG
=
ass4
CC
=
gcc
CC
=
gcc
CFLAGS
=
-std
=
c99
-pedantic
-Wall
-Wextra
# -
O3 -
D_POSIX_SOURCE
CFLAGS
=
-std
=
c99
-pedantic
-Wall
-Wextra
# -D_POSIX_SOURCE
LFLAGS
=
-lpthread
LFLAGS
=
-lpthread
OFILES
=
main.o
OFILES
=
main.o
RM
=
rm
-f
RM
=
rm
-f
ifdef
DEBUG
CFLAGS
+=
-ggdb
else
CFLAGS
+=
-O3
endif
$(PROG)
:
$(OFILES)
$(PROG)
:
$(OFILES)
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$(OFILES)
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$(OFILES)
...
...
os/ass4/ass4
deleted
100755 → 0
View file @
834a9bcd
File deleted
os/ass4/main.c
View file @
61825fd6
...
@@ -2,33 +2,46 @@
...
@@ -2,33 +2,46 @@
#include "stdlib.h"
#include "stdlib.h"
#include "pthread.h"
#include "pthread.h"
/* temporary include: */
#include <unistd.h>
#include <unistd.h>
int
forks_len
;
int
forks_len
;
pthread_mutex_t
*
forks
;
pthread_mutex_t
*
forks
;
pthread_cond_t
wait_threshold
;
pthread_cond_t
wait_threshold
;
typedef
struct
diner_stats
{
int
meals
;
}
diner_stats
;
int
count
=
0
;
int
count
=
0
;
#define COUNT_LIMIT 12
#define COUNT_LIMIT 12
void
*
philo_start
(
void
*
t_id
)
{
void
*
philo_start
()
{
printf
(
"P #%d: hello everybody!
\n
"
,
(
int
)
t_id
);
int
t_id
=
pthread_self
();
printf
(
"P #%d: hello everybody!
\n
"
,
t_id
);
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
// Let each philosopher take a random fork.
// Let each philosopher take a random fork.
int
f
=
rand
()
%
forks_len
;
//int f = rand() % forks_len;
pthread_mutex_lock
(
&
forks
[
f
]);
//pthread_mutex_lock(&forks[f]);
pthread_mutex_lock
(
&
forks
[
t_id
]);
pthread_mutex_lock
(
&
forks
[(
t_id
+
1
)
%
forks_len
]);
//while( pthread_mutex_trylock(&forks[(t_id+1) % forks_len]) ) {
// pthread_mutex_unlock(&forks[t_id]);
// Check the value of count and signal waiting thread when condition is
// // Check the value of count and signal waiting thread when condition is
// reached. Note that this occurs while mutex is locked.
// // reached. Note that this occurs while mutex is locked.
pthread_cond_signal
(
&
wait_threshold
);
// //pthread_cond_signal(&wait_threshold);
// sleep(1);
// pthread_mutex_lock(&forks[t_id]);
//}
// Do something useless
// Do something useless
printf
(
"P #%d: I'm eating.
\n
"
,
(
int
)
t_id
);
printf
(
"P #%d: I'm eating.
\n
"
,
t_id
);
sleep
(
1
);
pthread_mutex_unlock
(
&
forks
[
f
]);
pthread_mutex_unlock
(
&
forks
[
t_id
]);
pthread_mutex_unlock
(
&
forks
[(
t_id
+
1
)
%
forks_len
]);
}
}
pthread_exit
(
NULL
);
pthread_exit
(
NULL
);
...
@@ -38,10 +51,11 @@ void host_start(int philos) {
...
@@ -38,10 +51,11 @@ void host_start(int philos) {
pthread_attr_t
attr
;
pthread_attr_t
attr
;
pthread_t
*
threads
=
malloc
(
philos
*
sizeof
(
pthread_t
));
pthread_t
*
threads
=
malloc
(
philos
*
sizeof
(
pthread_t
));
forks
=
malloc
(
philos
*
sizeof
(
pthread_mutex_t
));
forks
=
malloc
(
philos
*
sizeof
(
pthread_mutex_t
));
diner_stats
*
stats
=
malloc
(
philos
*
sizeof
(
diner_stats
));
forks_len
=
philos
;
forks_len
=
philos
;
int
rc
;
void
*
status
;
void
*
status
;
int
rc
;
// POSIX standard specifies that threads are joinable by default, but
// POSIX standard specifies that threads are joinable by default, but
// unfortunately, not all pthread implementations set threads as joinable by
// unfortunately, not all pthread implementations set threads as joinable by
...
@@ -52,14 +66,18 @@ void host_start(int philos) {
...
@@ -52,14 +66,18 @@ void host_start(int philos) {
pthread_cond_init
(
&
wait_threshold
,
NULL
);
pthread_cond_init
(
&
wait_threshold
,
NULL
);
// Create the cutlery.
// Create the cutlery.
for
(
int
i
=
0
;
i
<
philos
;
i
++
)
for
(
int
i
=
0
;
i
<
philos
;
i
++
)
{
pthread_mutex_init
(
&
forks
[
i
],
NULL
);
pthread_mutex_init
(
&
forks
[
i
],
NULL
);
stats
[
i
].
meals
=
0
;
}
// Invite the philosophers.
// Invite the philosophers.
for
(
int
i
=
0
;
i
<
philos
;
i
++
)
{
for
(
int
i
=
0
;
i
<
philos
;
i
++
)
{
printf
(
"Host: inviting philo #%d
\n
"
,
i
);
printf
(
"Host: inviting philo #%d
\n
"
,
i
);
if
(
(
rc
=
pthread_create
(
&
threads
[
i
],
&
attr
,
philo_start
,
(
void
*
)
i
))
)
{
rc
=
pthread_create
(
threads
+
i
,
&
attr
,
philo_start
,
(
void
*
)
&
stats
[
i
]);
if
(
rc
)
{
fprintf
(
stderr
,
"pthread_create() returned: %d
\n
"
,
rc
);
fprintf
(
stderr
,
"pthread_create() returned: %d
\n
"
,
rc
);
exit
(
-
1
);
exit
(
-
1
);
}
}
...
...
paper/paper.tex
View file @
61825fd6
TT
\documentclass
[twocolumn]
{
article
}
\documentclass
[twocolumn]
{
article
}
\usepackage
{
url
}
\usepackage
{
url
}
\title
{
Web-based digital examination for specific learning areas
}
\title
{
Web-based digital examination for specific learning areas
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment