Need Urgent Help!!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Need Urgent Help!!!!

  1. #1
    Join Date
    Nov 2007
    Posts
    2

    Need Urgent Help!!!!

    "Implement an Alarm class. Threads will call your Pause(int time) to go to sleep for a period of time. You can use the Java Timer class. When timer interrupt goes off, the Timer interrupt handler must wake up any thread sleeping in Pause whose interval has expired. It is not required that an awakened thread starts running immediately after the interval expires. Just have them wake up after they have waited for at least the specified interval, time"

    How do I approach this? Please help me! It's very urgent.
    Does it need to be synchronized? Why? How?

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Welcome to DevX

    What have you got so far?

    (Is this a school assignment?)
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Nov 2007
    Posts
    2

    Reply

    Yes, it is a school assignment.
    I found the following, which I believe must be close to what's required but I don't fully understand what the following piece of code does. I don't know what's missing there. I don't understand where the sychronization should take place and how. If you can give me a brief explanation I'd really appreciate it. Thank you.

    http://www.koders.com/java/fid22FAD8...%3asemap*.java
    Code:
    package nachos.threads;
    
    import nachos.machine.*;
    
    /**
     * Uses the hardware timer to provide preemption, and to allow threads to sleep
     * until a certain time.
     */
    public class Alarm {
        /**
         * Allocate a new Alarm. Set the machine's timer interrupt handler to this
         * alarm's callback.
         *
         * <p><b>Note</b>: Nachos will not function correctly with more than one
         * alarm.
         */
        public Alarm() {
    	Machine.timer().setInterruptHandler(new Runnable() {
    		public void run() { timerInterrupt(); }
    	    });
        }
    
        /**
         * The timer interrupt handler. This is called by the machine's timer
         * periodically (approximately every 500 clock ticks). Causes the current
         * thread to yield, forcing a context switch if there is another thread
         * that should be run.
         */
        public void timerInterrupt() {
    	KThread.currentThread().yield();
        }
    
        /**
         * Put the current thread to sleep for at least <i>x</i> ticks,
         * waking it up in the timer interrupt handler. The thread must be
         * woken up (placed in the scheduler ready set) during the first timer
         * interrupt where
         *
         * <p><blockquote>
         * (current time) >= (WaitUntil called time)+(x)
         * </blockquote>
         *
         * @param	x	the minimum number of clock ticks to wait.
         *
         * @see	nachos.machine.Timer#getTime()
         */
        public void waitUntil(long x) {
    	// for now, cheat just to get something working (busy waiting is bad)
    	long wakeTime = Machine.timer().getTime() + x;
    	while (wakeTime > Machine.timer().getTime())
    	    KThread.yield();
        }
    }
    Last edited by Hack; 11-19-2007 at 09:14 AM. Reason: Added Code Tags

Similar Threads

  1. VB.net beginner (very urgent)
    By devsriram in forum .NET
    Replies: 5
    Last Post: 11-02-2006, 06:57 AM
  2. how to create Dynamic linkbutton - Very urgent
    By bakkiyraj in forum ASP.NET
    Replies: 1
    Last Post: 10-08-2005, 06:20 AM
  3. Replies: 1
    Last Post: 05-21-2005, 11:11 AM
  4. URGENT.. URGENT... PLEASE HELP US
    By precious in forum Enterprise
    Replies: 2
    Last Post: 06-23-2001, 02:34 PM
  5. Urgent - How to get the free space on a drive
    By Giraudet in forum ASP.NET
    Replies: 0
    Last Post: 01-22-2001, 10:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center