Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 83917

Summary: [Progress] Automatic transfer of scheduling rules when spwaning modal context thread
Product: [Eclipse Project] Platform Reporter: Dirk Baeumer <dirk_baeumer>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: RESOLVED WONTFIX QA Contact: Prakash Rangaraj <prakash>
Severity: enhancement    
Priority: P5 CC: john.arthorne, martinae, susan
Version: 3.1Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Dirk Baeumer CLA 2005-01-28 06:11:26 EST
With IJobManager#transferRules and IThreadListener it is currently possible to
transfer rules from the UI thread to the modal context thread. However, this is
still error prone since the code spawning the modal context thread may not know
about scheduling rules allocated outside of his scope. Consider the following
example:

IJobManager#beginRule(rule).
ExistingOperation#do()
IJobManager#endRule()

ExisitingOperation#do() {
  IRunnableContext#run(......);
}

to make sure that this doesn't end in a dead lock the operation has to pass all
the scheduling rules to the modal context thread.

Couldn't this be done automatically by the ModelContext using the API
IJobManager#getCurrentJob()#getSchedulingRule()
Comment 1 John Arthorne CLA 2005-01-28 16:44:54 EST
Are you suggesting that we automatically transfer the scheduling rule owned by
the UI thread every time a modal context thread is created?

Note that JFace has no dependency on the job API (and won't be adding such a
dependency).
Comment 2 Dirk Baeumer CLA 2005-01-31 04:56:13 EST
Yes, that's what I was asking for. If the UI thread is blocked after wards it
doesn't make sense to keep any rules. If someone does a sync exec back from the
modal context he can transfer the rules back.

However, JFace not knowing about Jobs makes this difficult. But the pltform
could plug-in a special rule tranferer.
Comment 3 John Arthorne CLA 2005-01-31 10:11:58 EST
I'm not really keen on this idea.  Owning locks and scheduling rules in the UI
thread is generally bad because it prevents the UI from painting if the lock or
rule is not available.  We get around this by spinning a "free" event loop when
the UI is blocked, but this has its own problems.  I don't want to add any API
that suggests owning locks in the UI thread is an acceptable thing to do.
Comment 4 Martin Aeschlimann CLA 2005-02-01 04:37:04 EST
Dirk, why does the refactoring aquire locks already in the UI-thread?

The current situation is a guaranteed source of deadlocks.
As users of IRunnableContext.run(forked) can not make any assumtions about the
locks held by their thread they must transfer them otherwise, it is a
programming error.

Isn't it the whole concept of the model context thread to run forked so that the
UI can still be updated (and you don't have to run a extra event loop)?
So maybe the locks should get moved, (not copied -> freed on the UI thread).
Whouldn't it be better if the Job framework manages all that and doesn't let
JFace create its own thread?
Comment 5 Dirk Baeumer CLA 2005-02-01 05:25:02 EST
Refactoring has to aquire the look in the UI thread. Otherwise it can't be
guaranteed that the workspace doesn't change during the refactoring steps
precondition checking, change creation and change execution. The actual
execution of these steps take place in the modal context thread.

John, what do you suggest then to solve this problem. Letting the client do all
the work (especially in cases where the client isn't aware of this at all)
doesn't seem to be the right solution either.
Comment 6 John Arthorne CLA 2005-02-03 11:14:37 EST
My point is that acquiring a rule in the UI thread is not the common case. 
Requiring the client to do a bit of work to manage this lock transition isn't
bad if refactoring is likely to be the only use case.
Comment 7 Martin Aeschlimann CLA 2005-02-03 11:54:14 EST
But the code spawning the modal context thread may not know
that it is called by something like refactoring. 
Comment 8 John Arthorne CLA 2005-02-03 18:14:35 EST
My model of how this works is that no real "work" happens in the UI thread.  The
rule is acquired in the UI thread, a dialog is displayed, and then the
refactoring infrastructure creates a modal context thread to perform the
precondition checks and the actual refactoring.  In this modal all the
participants are called from the modal context thread (in fact everything except
actually displaying the precondition and preview dialogs is in the non-UI thread).

From your description, it sounds like refactoring is calling participants in the
UI thread, and then the participants are responsible for forking the modal
context thread. Is there a particular situation where this is currently happening?
Comment 9 Tod Creasey CLA 2007-06-14 12:54:40 EDT
There are currently no plans to work on this although we would be happy to review a patch
Comment 10 Tod Creasey CLA 2007-06-14 12:55:04 EDT
Marking WONTFIX
Comment 11 Susan McCourt CLA 2009-07-09 19:36:40 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 12 John Arthorne CLA 2009-07-09 22:55:09 EDT
This was marked as WONTFIX. I don't know how it got reopened, as it doesn't show up as being reopened in the bug history.