dcsimg
Thread executing in CS got swapped out, What happens then?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   joseph_lam
Posted On:   Tuesday, August 14, 2001 07:57 PM

Suppose a thread enter a critical section or synchronization block, which means that it acquires the lock. At this point, the operating system decides to interrupt this thread and let other thread, perhaps of higher priority have the CPU. What happens to the lock? Is it released? My guess is that the first thread's context is saved when it's swapped out, without releasing the lock. So, the second higher priority would not be able to acquire the lock if it wants to. That means, a swapped out thread can still hold up a lock. Is this true? (Otherwise, the second thread can mess up the state on the "locked" object. And when the first thread comes back, it will see the "ghost" data. So I feel strongly that "A swapped ou   More>>

Suppose a thread enter a critical section or synchronization block, which means that it acquires the lock. At this point, the operating system decides to interrupt this thread and let other thread, perhaps of higher priority have the CPU. What happens to the lock? Is it released?

My guess is that the first thread's context is saved when it's swapped out, without releasing the lock. So, the second higher priority would not be able to acquire the lock if it wants to. That means, a swapped out thread can still hold up a lock. Is this true? (Otherwise, the second thread can mess up the state on the "locked" object. And when the first thread comes back, it will see the "ghost" data.

So I feel strongly that "A swapped out thread can still hold a lock on an object" is true.

Can anyone confirm this?

   <<Less

Re: Thread executing in CS got swapped out, What happens then?

Posted By:   Jonas_Gustafsson  
Posted On:   Friday, August 17, 2001 01:34 AM

Yes it's true that "A swapped out thread can still hold a lock on an object...".

This is what synchronization is all about. Once the lock is is fetched, no other thread can grab the lock until the first thread releases the lock. This has nothing to do with the priority of the threads.


If you want to read more, I can strongly recommend a book about threading:
JAVA Threads by Scott Oaks & Henry Wong



/j
About | Sitemap | Contact