Semaphore in os - operating-system

A semaphore is needed to effectively ensure that only one student (out of a class of three students) has access to the examination attendance at a time. When the 1st student is doing ‘write name’, 2nd student is doing ‘write book no’ and the 3rd student is doing ‘sign attendance’.

Related

UML Class Diagram: Attributes and methods dependant on two classes

I am trying to do a simple UML model about a car dealership.
The company has at least one store where in each they sell at least one type of a car. Each store has a name and each car has a name, type, and price. Each outlet also keeps stock of every car they sell.
I have outlined the idea in this image:
In addition to this, after every day, the number of cars sold gets recorded into a database. How would I add this to the model? Also, is there a better way to model the amount of cars in stock than to have it as a separate class? If there is a better diagram to model this type of scenario with I'd also be interested.
Thanks for any help!
There are many ways to model sales records. The simplest and most common is to have a sales ledger. It creates sales entries for items. The item is a separate (association) class that records the number of sold items, the price paid, the sales date, the sales person, and more. Pretty simple and straight forwards, until you get to the gory details. Ask your next dealer...
You can model a sales record as a separate class. Let's call it DaySales. Each day, you have a new instance of DaySales, containing the date and the amount of cars sold. I have given attribute date the data type 'String', because UML does not define a Date type. But if you define it yourself, you could better use Date than String.
I have removed the association between Car and Outlet, because it is already implicitly defined via Stock, but you can keep it as a redundant association, if you like.
I have altered the multiplicity of the association between Car and Stock, because there will be multiple cars in stock.

Vehicle Routing With Staff

I am working on a solution where we need to route our vehicle to locations of Tasks asked by our Customers. Here is how my domain looks like:
interface TaskOrVehicle{
#InverseShadowVarible Task nextTask;
getLocation();
}
Task:
#PlanningEntity
Class Task implements TaskOrVehicle{
#ChainedPlanningVariable TaskOrVehicle taskOrVehicle;
#PlanningVariable Staff staff;
#AnchorShadowVariable Vehicle vehicle;
}
So, I've got Staff and Vehicle as facts while Task is a planning entity. So with optaplanner, it schedules task in a chain but it assigns different employee to different tasks in same chain.
So, if A, B, C ,D and E are tasks and Staff st1,st2,st3 and Vechcle V1,V2 are there.
Ideal solution looks like:
V1->A(st1)->B(st1)->C(st1)
V2->D(st2)->E(st2)
But my solution looks like:
V1->A(st1)->B(st3)->C(st2)
V2->D(st3)->E(st2)
This is because I don't have employees chained and using employee as a planning variable. Now, I can fix it using rules that nextTask should have same employee as current task but that's a overkill.
What are the best practices I can do here so that every task chain has same employee?
Note:I don't want to keep employee in Vehicle as if Vehicle gets free it can be assigned to different employee for new task chain.

Event B Total Function

I have a question as follows:
A primary school class contains a number of children and a variety of books. Write a model which keeps track of the books that the children have read. It should maintain a relation hasread between children and books. It should also handle the following events:
record: adds the fact that the given child has read the given book
newbook: outputs a book that the given child has not already read
books_query: outputs the number of books the given child has read
Here is my model so far
CONTEXT
booksContext
SETS
STUDENTS
BOOKS
CONSTANTS
student
book
AXIOMS
axm1: partition(STUDENTS, {student})
axm2: partition(BOOKS,{book})
And my machine is as follows:
MACHINE
books
SEES
booksContext
VARIABLES
students
books
readBooks
INVARIANTS
students ⊆ STUDENTS
books ⊆ BOOKS
readBooks ∈ students → books
I have an event where I want mark a book as read for a given student. It takes in two parameters: the name of the student and the name of the book.
EVENTS
record
ANY
rbook
name
grd1: rbook ∈ books
grd2: name ∈ students
Now for the guards. I want to say
"If the student has not read the book already"
I had this but t doesn't work and I don't know what to do now. Can anyone help me
grd3: rbook(name) = ∅
rbook is just one book, but you are using is as if it was a function. Do you mean readBooks(name) = {}? If yes, the statement would still be "Has the student never read a book?".
The first problem is probably in the definition of readBooks. You modelled it as a total function from students to books. That means that every student has read exactly one book. That is probably not what you wanted to express. To state that every student has read an arbitrary number of books you can map students to sets of books:
readBooks : students --> POW(books)
The the guard would be rbook /: readBooks(name).
Personally I would prefer relations in such a case, they are usually easier to cope with. Here a pair s|->b would be in readBooks if student s has read book b:
readBooks : students <-> books
In that case the guard would be name|->rbook /: readBooks.

OO Design and the data model for change log function

: EJB 3, JPA (EcipseLink) and Oracle Database
An application has two entities: Group and Person. There is a one-to-many relationship.
The requirement is, that every changes of Group and Person must be saved for later to roll or show.
The 1st idea:
make the id and timestamp of the change/create as a composite primary key for Group and Person.
Every change will create a new object with the same id and new timestamp. For Example, a Group hat been changed, then create a new Group. but the relationship between Group and Person unchange. Here hat a problem: the constrait "one-to-many" will breaked!. Now one person hat the relation to two groups with the same id.
The 2nd idea:
for Group and Person create two another Entities GroupArchive and PersonArchive. In Group and Person only the lastest Infomation. Any changes will be copied and saved to Archive Entities. Between Group and GroupArchive hat a one-to-many relationship. And same for Person and PersonArchive.
Are my ideas realizable? Has anybody a better idea?

Manually creating intermediate table in a many to many relationship for Core - Data

I'm currenty working with Core-data for an iPhone project.
But I'm a bit confused about one element.
With Core Data currently you do not need to create the intermediate table when creating many to many relationships (its all handled behind the scenes by core data)
But in my case I actually need some attributes on my many to many relationship!
For example
I have a table called Students
and another table called Lessons
a Student can be in many lessons
and a lesson can have many students
Now a standard many to many relationship will not work for me as I actually need to define more details on the join, i.e. StartDate and LeaveDate.
In a standard sql model for example my join table would be something like
StudentLessons (Studentid, LessonId, StartDate, LeaveDate )
I would need these properties as when i'm querying for information I will need the details from the join to filter my results.
How can I create this in core data and also filter for results?
I've seen folks say that you would actually create the StudentLesson entity manually in core data.
Now if I did this would I just have the attributes (Startdate, LeaveDate) and then a one to many relationship from the Student and then the Lessons table?
Student - > StudentLessons
Lesson - > StudentLessons
I guess I'm a bit confused on how I would go about making sure that the relationships and the content of the relationships are setup correctly. (i.e If I add an Student object to the StudentLessons - how would I then assign/add the Lesson.)
Sorry this is my first time playing with Core Data.
Takes a bit o getting used to when coming from a full on sql background.
You are absolutely right. The correct way to do this is to create a new entity like StudentLessons. Let's call it Attendance. It should have the startDate and endDate, and two relationships.
The relationship to the student can be many-to-many, unless it is foreseeable that startDate and endDate are always different for each student. One Attendance with its dates can have many students in it. One student can have several Attendance duties.
Student <<---->> Attendance
Clearly, the relationship to Lesson should be one-to-many. One Lesson can have different Attendance configurations, with different dates. But each Attendance belongs only to one Lesson.
Lesson <---->> Attendance
To address your question, you can make the Attendance attribute of Lesson non-optional (and vice versa), this way it will ensure that each Lesson has at least one Attendance with appropriate dates, and each Attendance has exactly one Lesson.
I think your can remove the link between Student and Lesson. Just assign an Attendance rather than a lesson. If you want a Lesson assigned to a Student without dates, just allow Attendance to have NULL as those properties.
TheTiger,
Just because Core Data will create a join table for you, that doesn't mean you have to use it. Maintaining which student succeeds with which lesson is just the same except you will create the intermediate entity and then use the appropriate setters to build the relationships.
You will have to use more key paths and do relationship prefetching but those are straightforward to do.
Andrew