Difference between revisions of "lensowiki:Sandbox"

From lensowiki
Jump to: navigation, search
Line 1: Line 1:
 
This can be used for testing out wiki markup. Enjoy.
 
This can be used for testing out wiki markup. Enjoy.
 
----
 
----
Mr. Smith serves as Chairman and as a member of the Investment Committee of all Keystone-managed funds. Prior to co-founding Keystone, Mr. Smith was Chairman and CEO of VistaCare, Inc., a venture capital-funded healthcare company he founded and guided through its initial public offering. Prior to VistaCare, Mr. Smith was Chairman and CEO of ValueRx, Inc. one of the largest pharmacy benefit management companies in the U.SMr. Smith has also held senior positions at Advance PCS and Baxter Healthcare and is currently a director of Magellan Health Services (NASDAQ:  MGLN), the largest independent behavioral health care company in the United States. He is also a director of multiple privately held companies.
+
==Questions 1 - Thread.Join()==
 
+
Implementation:
Mr. Earl is active in fund selection, due diligence, and the general management of the firm.  Mr. Earl was previously a senior investment banker with Lehman Brothers, where he worked closely with senior management of numerous private equity and venture capital firms. While at Lehman Brothers, Mr. Earl was active in evaluating and executing a broad variety of direct investment opportunities and monetization strategies including initial public offerings, secondary equity offerings, recapitalizations and company sale transactionsPrior to joining Lehman Brothers, Mr. Earl held previous investment banking and structured finance positions at Dillon, Read & Co., Inc. and Credit Suisse.
+
KThread has a new state variable joinedOnMe, a ThreadQueue.
 
+
Mr. Nielson is active in fund selection, due diligence and the general management of the firmHe was previously Managing Director of Regional Investment Partners, a private equity research firm focused on identifying and benchmarking the nation’s top small and lower-middle market buyout fund managers. Mr. Nielson also served as a Vice President at Partners Group, a leading private equity fund of funds with over $8 billion in private equity and hedge fund programsBased in the firm’s New York office, Mr. Nielson played a key role in building Partners Group’s U.S. presence and in identifying and performing due diligence on U.S. investment opportunities, including buyout fund investments, secondaries and direct co-investmentsHe later worked at Partners Group’s headquarters in Switzerland where he was active in private equity fund formation and structuring. Prior to his time at Partners Group, Mr. Nielson worked for the accounting firm KPMG and is a Certified Public Accountant.
+
If (CurrentThread == self or joinedOnMe != null){
 
+
        Return;                // conditions for join not satisfied
Lynette has several years of experience in public, industry and private entity accounting and served as the Chief Financial Officer for B&J Smith Investments, a family office based on Scottsdale, Arizona.  In her position as CFO, she oversaw the financial management and reporting of various investments and operating companiesPrior to B&J Smith Investments, Lynette was a senior accountant in financial reporting at Arizona Public Service Company, a public utility located in Phoenix, Arizona and was an auditor for Deloitte and Touche. Lynette is a Certified Public Accountant.
+
} else if (status == Finished){
 
+
Return;
Mr. Widmann has been an active member of the U.S. financial community as a lawyer, venture capitalist and investment banker since 1964. He was a Principal of the investment banking firm of Tanner & Co., Inc. from 1996 to 2004 and served as Chairman of Lydall, Inc. (LDL), a manufacturer of thermal, acoustical and filtration materials. He currently serves as director of several additional NYSE listed companies.
+
}
 
+
Else {
From 1986 to 1995, Mr. Widmann was a Senior Managing Director of Chemical Banking Corporation (now JPMorgan Chase Corporation). Prior to joining Chemical, Mr. Widmann was a founder and CEO of First Reserve Corporation, the largest independent energy investing firm in the U.S., and served as a director at First Reserve Corporation for 15 years.
+
currentThread.sleep;
 
+
joinedOnMe = currentThread;
He has been a senior moderator of the Executive Seminar in the Humanities at The Aspen Institute since 1990 and has been a Director of the March of Dimes of Greater New York since 1988. He is also a Director of Oxfam America, an affiliate of Oxfam International, the global humanitarian and crisis relief organization. Mr. Widmann earned a B.A. degree from Brown University, cum laude, and a J.D. Degree from Columbia Law School.
+
}
 +
 +
Finished(){
 +
 +
joinedOnMe.ready();
 +
}
 +
 +
Testing:
 +
ThreadA prints out a few statements, calls ThreadB.join(), then prints out a few more statements. ThreadB also prints out a series of statements. We want to check that ThreadB executes contiguously to completion before ThreadA resumes its execution.
 +
   
 +
==Question 2 - Condition2==
 +
Implementation:
 +
Condition2 has a new state variable waitQueue, a ThreadQueue of Threads transferPriority false.
 +
In the sleep() method we add the calling (current) thread to the waitQueue of threads. After the thread releases its condition lock, we disable interrupts and it is put to sleep. When it wakes up, interrupts are re-enabled and the thread attempts to reacquire the condition lock.
 +
   
 +
In the wait() method, if the waitQueue is not empty we ;
 +
Sleep(){
 +
disableInterrupts
 +
waitQueue.waitforaccess(currentThread) // WAITFORACCESS
 +
conditionLock.release
 +
currentThread.sleep
 +
conditionLock.acquire
 +
enableInterrupts
 +
}
 +
Wake(){
 +
Disable interrupts
 +
Nt = waitqueue .nextthread
 +
        If (nt is not null){
 +
Ready nt
 +
}
 +
Re-enable interrupts
 +
 +
wakeAll
 +
while (waitqueue.nextthread != null)
 +
wake()
 +
 +
Testing: DO MOE
 +
   
 +
==Question 3 - WaitUntil()==
 +
Implementation:
 +
Alarm has a new sorted PriorityQueue waitingThreads to keep track of when waiting threads should be woken, sorted on their wake times from lowest to highest.
 +
It also has a new inner class named waitingThread which contains a reference to the KThread and its associated wakeTime(long).
 +
 +
 +
   
 +
waitUntil(time){
 +
WaitingThread wt = new WaitingThread (currentThread, currentTime + time);
 +
waitingThreads.add (wt);
 +
currentThread.sleep;
 +
}
 +
 +
timerInterrupt(){
 +
while (WaitingThreads.peek().time <= currentTime){
 +
WaitingThreads.pop().wake();
 +
}
 +
   
 +
Class WaitingThread (){
 +
KThread currentThread;
 +
Long time;
 +
}
 +
   
 +
Testing:
 +
For or while loop that prints out a series of statements. Check that statements for different threads are all printed contiguously according to their respective wake times.
 +
 +
==Question 4 - Communicator==
 +
Implementation:
 +
We recognize the invariant that there will always be an unequal amount of speakers and listeners, because speakers and listeners are almost immediately paired off and return. The S/L on the larger queue will acquire lock, perform their actions, wake opposing queue and immediately return (if they slept they would be put on the end of the queue). S/L on smaller queue will acquire lock, perform their actions, sleep, and once woken up again by opposing queue, return.
 +
   
 +
Special condition for 1 on 1. Use a Boolean flag which indicates a transfer is in progress. The 2nd S/L will set the flag to true, perform its actions and wake the 1st S/L; any intruding 3rd S/L will not attempt to acquire the lock as long as this flag is true—this 3rdSL will sleep in its respective queue. The 1st S/L will be woken up by the 2nd S/L, set the Boolean to false, and return.
 +
 +
Testing: DO ME.
 +
 +
==Question 5 - Priority Scheduler==
 +
PriorityQueue
 +
----
 +
NextThread get most important member off Priority and Time queue. LastThread variable is set when NextThread or acquire is called. Also triggers recalculation on popped off LastThread and popped off thread which becomes the LastThread.
 +
 +
PickNextThread inspect first thread without removing it and return ThreadState.
 +
 +
New Instance variable of effectivepriority
 +
GetEffectivePriority returns cached effective priority of a thread capped @ maxpriority
 +
 +
SetPriority
 +
Change actual priority of current thread
 +
Change effective priority of lastthread by difference between current threads priority and new priority.
 +
 +
If set priority is called on a thread with effective priority must make sure effective priority is still present, ex: 5+5, set priority to 0, thread should still have 5.
 +
 +
Make sure to check for transfer priority—procedure is different: ex: always return regular priority if transferpriority== false
 +
 +
 +
PriorityScheduler.waitforaccess(thread)
 +
 +
 +
ThreadState.WaitForAccess(priorityQueue)
 +
Put thread onto time&priority wait queue. Sorts all by priority , time.
 +
Recalculates effective priority.
 +
 +
Acquire
 +
recalculate LastThread effective priority.
 +
Set CurrentThread = LastThread and recalculate priority.
 +
 +
Recalculation: iterate through structure and add up all priorities.
 +
 +
 +
When thread calls threadstate.acquire you get donation of all threads on waitqueue
 +
Three things that change your priority: when another thread is added to queue waiting on you, when you acquire, when you release
 +
Use treeset to keep track of all threads sorted on time
 +
 +
Every thread has a cached effective priority integer
 +
Set when acquire / next thread
 +
Wait for thread doesn’t call calculate priority on itself, calls calculate priority on current thread
 +
Waitforaccess add to something that keeps track of priority and time
 +
 +
TESTING: DO ME.
 +
 +
==Question 6 - Boat==
 +
CHILD who thinks he’s the last person must sleep, but communicate to begin and say he’s done. In that case, pilot must go to sleep instead of immediately piloting back.
 +
# of children seen == # of children gone
 +
 +
            TESTING: set up some test cases i.e. 2 children 0 adults, 2 children 1 adult, 2 children 2 adults, 3 children 2 adults, 5 children 3 adults and work them out mathematically. then verify that threads execute the same solution.

Revision as of 22:33, 24 September 2008

This can be used for testing out wiki markup. Enjoy.


Questions 1 - Thread.Join()

Implementation: KThread has a new state variable joinedOnMe, a ThreadQueue.

If (CurrentThread == self or joinedOnMe != null){

       Return;                 // conditions for join not satisfied

} else if (status == Finished){ Return; } Else { currentThread.sleep; joinedOnMe = currentThread; }

Finished(){ … joinedOnMe.ready(); }

Testing: ThreadA prints out a few statements, calls ThreadB.join(), then prints out a few more statements. ThreadB also prints out a series of statements. We want to check that ThreadB executes contiguously to completion before ThreadA resumes its execution.

Question 2 - Condition2

Implementation: Condition2 has a new state variable waitQueue, a ThreadQueue of Threads transferPriority false. In the sleep() method we add the calling (current) thread to the waitQueue of threads. After the thread releases its condition lock, we disable interrupts and it is put to sleep. When it wakes up, interrupts are re-enabled and the thread attempts to reacquire the condition lock.

In the wait() method, if the waitQueue is not empty we ; Sleep(){ disableInterrupts waitQueue.waitforaccess(currentThread) // WAITFORACCESS conditionLock.release currentThread.sleep conditionLock.acquire enableInterrupts } Wake(){ Disable interrupts Nt = waitqueue .nextthread

       If (nt is not null){

Ready nt } Re-enable interrupts

wakeAll while (waitqueue.nextthread != null) wake()

Testing: DO MOE

Question 3 - WaitUntil()

Implementation: Alarm has a new sorted PriorityQueue waitingThreads to keep track of when waiting threads should be woken, sorted on their wake times from lowest to highest. It also has a new inner class named waitingThread which contains a reference to the KThread and its associated wakeTime(long).


waitUntil(time){ WaitingThread wt = new WaitingThread (currentThread, currentTime + time); waitingThreads.add (wt); currentThread.sleep; }

timerInterrupt(){ while (WaitingThreads.peek().time <= currentTime){ WaitingThreads.pop().wake(); }

Class WaitingThread (){ KThread currentThread; Long time; }

Testing: For or while loop that prints out a series of statements. Check that statements for different threads are all printed contiguously according to their respective wake times.

Question 4 - Communicator

Implementation: We recognize the invariant that there will always be an unequal amount of speakers and listeners, because speakers and listeners are almost immediately paired off and return. The S/L on the larger queue will acquire lock, perform their actions, wake opposing queue and immediately return (if they slept they would be put on the end of the queue). S/L on smaller queue will acquire lock, perform their actions, sleep, and once woken up again by opposing queue, return.

Special condition for 1 on 1. Use a Boolean flag which indicates a transfer is in progress. The 2nd S/L will set the flag to true, perform its actions and wake the 1st S/L; any intruding 3rd S/L will not attempt to acquire the lock as long as this flag is true—this 3rdSL will sleep in its respective queue. The 1st S/L will be woken up by the 2nd S/L, set the Boolean to false, and return.

Testing: DO ME.

Question 5 - Priority Scheduler

PriorityQueue


NextThread get most important member off Priority and Time queue. LastThread variable is set when NextThread or acquire is called. Also triggers recalculation on popped off LastThread and popped off thread which becomes the LastThread.

PickNextThread inspect first thread without removing it and return ThreadState.

New Instance variable of effectivepriority GetEffectivePriority returns cached effective priority of a thread capped @ maxpriority

SetPriority Change actual priority of current thread Change effective priority of lastthread by difference between current threads priority and new priority.

If set priority is called on a thread with effective priority must make sure effective priority is still present, ex: 5+5, set priority to 0, thread should still have 5.

Make sure to check for transfer priority—procedure is different: ex: always return regular priority if transferpriority== false


PriorityScheduler.waitforaccess(thread)


ThreadState.WaitForAccess(priorityQueue) Put thread onto time&priority wait queue. Sorts all by priority , time. Recalculates effective priority.

Acquire recalculate LastThread effective priority. Set CurrentThread = LastThread and recalculate priority.

Recalculation: iterate through structure and add up all priorities.


When thread calls threadstate.acquire you get donation of all threads on waitqueue Three things that change your priority: when another thread is added to queue waiting on you, when you acquire, when you release Use treeset to keep track of all threads sorted on time

Every thread has a cached effective priority integer Set when acquire / next thread Wait for thread doesn’t call calculate priority on itself, calls calculate priority on current thread Waitforaccess add to something that keeps track of priority and time

TESTING: DO ME.

Question 6 - Boat

CHILD who thinks he’s the last person must sleep, but communicate to begin and say he’s done. In that case, pilot must go to sleep instead of immediately piloting back.

  1. of children seen == # of children gone
           TESTING: set up some test cases i.e. 2 children 0 adults, 2 children 1 adult, 2 children 2 adults, 3 children 2 adults, 5 children 3 adults and work them out mathematically. then verify that threads execute the same solution.