Coder Social home page Coder Social logo

tv-program-simulator's Introduction

This was our project for the operating systems course.
Firstly, all of the parts (1, 2, logging) are working properly.

1-2) Here, we initialize gettimeofday. We then initialize the values we have taken with arguements.
We created tvQueue which is the queue for commentors with the size of commentors*q*2 to make sure 
enough room is existing. We then opened threads for each commentor and called commentor method for
each, did same thing for moderator and observer. In the main, we look if there will be event generated,
for every second with probability.
	In the moderator, if there is no question currently, we locked all the commentors with mutex_lock
moderator checks if there is event and if no asks a question. In a while loop moderator waits for commen-
tors to make their decisions for answering. Then for each commentor in the tvQueue which holds current 
commentors willing to speak, at each one waits if currently commentor is talking and after that unlocks the
lock of the next commentor on the queue, pops them and that commentor is speaking. After all commentors in
queue has spoken, locks of each commentor is unlocked so that they can make their decision for the next 
question.
	Commentor waits for questions to be asked in a while. With rand() commentor decides with probability,
p if they will answer and adds themself to list if so, we used lock here so that that two distinct commentors
do not try to modify list at the same time. It controls if there is event and doesn't speak if so. If it is 
time for commentor to speak then they speak and if all commentors had their turns to speak this doesn't execute.
	Observer checks for event and if there is, it cancels the sleep of commentor that is currently speaking 
with the pthread_cond_timedwait and that commentor is cut short, we also logged that. It locks the event mutex
and everyone waits for that mutex to be unlocked. 

3) This was the by far easiest one to make since we half implemented logs (such as prints etc.)
in order to bugfix and see if everything is working as intended. Whenever moderator creates a
question we log it with the relative time to start. Relative time is implemented as we store the
start of the program as long long type structure with the getTime() method as miliseconds. Whenever
we try to log some event we deduct the event time from the start time and with some modification,
we show it as min:sec:msec format in the left side. Whenever commentor generates comment and speaks,
we also logged them. If breaking news occur, it is logged as print. When breaking news end, it is 
logged and also if commentor is cut, it is also written.

tv-program-simulator's People

Contributors

berkecanrizai avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.