summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo <mokha@cisco.com>2016-06-23 13:00:52 -0400
committermo <mokha@cisco.com>2016-06-23 13:00:52 -0400
commit00cd966011e8d68bcae0d730e8c58886c8327e7c (patch)
tree771a1d54be03c8134a7531c8240d5e009f7e068a
parent5b1e4d4a645ad152358c999fae79f4ae337b9128 (diff)
complete lab 5
-rw-r--r--lab05/procs.c10
-rw-r--r--lab05/sched.c18
-rw-r--r--lab05/threads.c17
3 files changed, 26 insertions, 19 deletions
diff --git a/lab05/procs.c b/lab05/procs.c
index 9128b19..cf1a9ff 100644
--- a/lab05/procs.c
+++ b/lab05/procs.c
@@ -6,13 +6,9 @@ int global;
int main()
{
- /*
- Have the parent fork() a child twice
- Use the return value of fork() to make sure you're the
- parent before forking a second child
- */
-
- /* Your code here */
+ if (fork()) { /* only the 1st parent enters here */
+ fork(); /* ...to fork() a 2nd child... */
+ }
/* All 3 processes (parent and children) run the following */
diff --git a/lab05/sched.c b/lab05/sched.c
index ee0d1ac..6dee154 100644
--- a/lab05/sched.c
+++ b/lab05/sched.c
@@ -61,6 +61,24 @@ int main(void)
int two=2;
/* Add your scheduler setup logic here */
+ pthread_attr_init(&attr);
+ pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+
+ /* Use this line for the first run only */
+// pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
+ /* End of first run only code */
+
+ /* Use these lines for the second run only */
+// pthread_attr_setschedpolicy(&attr, SCHED_RR);
+// param.sched_priority = 10;
+// pthread_attr_setschedparam(&attr, &param);
+ /* End of second run only code */
+
+ /* Use these lines for the third run only */
+ pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+ param.sched_priority = 10;
+ pthread_attr_setschedparam(&attr, &param);
+ /* End of third run only code */
if (pthread_create(&t1, &attr, thread, &one)) exit(1);
if (pthread_create(&t2, &attr, thread, &two)) exit(1);
diff --git a/lab05/threads.c b/lab05/threads.c
index feee49c..d010349 100644
--- a/lab05/threads.c
+++ b/lab05/threads.c
@@ -34,24 +34,17 @@ int main(void)
if (pthread_attr_init(&attr)) {
exit(1);
}
- if (pthread_attr_setschedpolicy(&attr, SCHED_OTHER)) {
+ if (pthread_attr_setschedpolicy(&attr, SCHED_RR)) {
exit(1);
}
/* Start 3 threads */
prev_thr_id = 0;
for (x=0; x<3; x++) {
- /*
- Fill in the code ala ...
- if (pthread_create(&currentThreadID, &attribute,
- thread, (void*)previousThreadID)) {
- exit(1);
- }
- */
-
- /* insert your code here */
-
- prev_thr_id = curr_thr_id;
+ if (pthread_create(&curr_thr_id, &attr, thread, (void*)prev_thr_id)) {
+ exit(1);
+ }
+ prev_thr_id = curr_thr_id;
}
/* Join last thread */