I want to wirte an elevator program(simulating the real one) with OF.It’s my Operating System homework.
But the tutorials of ofThread is not very clear,I can’t get the point.
Can anyone give me an example of how to use the ofThread functions?
Thanks!
What in the ofThread example is giving your trouble?
In general, to create a threaded object:
-
you extend the ofThread class
-
you insert the needed functionality
-
you design your way to submit and get content to/from the thread (using the lock/unlock mechanism)
-
you create your threaded loop into the threadedFunction()
If any of the these points is not clear, just ask
Now I have 3 elevators,how can I get these system running?
elevator:There are 20 floors.The elevators are supposed to react in the normal way as in our daily life.Now I have programmed all the functions that can control every details of the movements(move_to_target_floor,decide_which_floor_elevator_is etc)
I have no idea how to schedule the progress.
More specific:
(1)the tutorial(of OFx) has an exit function,but it is defined by ourselves ,I assume it doesn’t work at all.So Where to add the stopThread?
(2)Now I have class:“Panel”,“button”,“ele”.Do I need to launch a new class to schedule the thread?
Looking at your code, I think the most reasonable thing to do would be making the ele class extend ofThread, just like myThread does in the tutorial
To reply to your question regarding the exit function you see in the example: in the average OF application, ofApp extends the basic ofBaseApp class, so that you can customise it to fit your needs. ofApp::exit, is inherited from ofBaseApp and is just the normal OF exit function, called just before closing the app: the example shows you that you should stop your custom thread before closing.
Finally a note: a separate thread is not really needed to create your elevator simulation; so, if you’re using this scenario to learn threads, ok, go ahead, but if you just want to draw simulated elevators, you can do it without dealing with multithreading
Many thanks~~~ Your detailed reply is of great help to me!
I’m just a greenhand on this…So lots of things may be little bit confusing