librelist archives

« back to archive

Question about Thread in JRuby and SWT

Question about Thread in JRuby and SWT

From:
ashbb
Date:
2012-03-10 @ 06:16
Hi all,

I have a question about a small snippet written in JRuby and SWT.

Try out this snippet: https://gist.github.com/2010465

This snippet works. A red rectangle will appear on a window.
But, after deleting number sign `#`s , I mean using `Thread`, nothing
appear.

Why??

ashbb

Re: [shoes] Question about Thread in JRuby and SWT

From:
Régis d'Aubarède
Date:
2012-03-15 @ 11:57
Hello ashbb,

SWT is not thread safe.
In java, threaded code (ie code in thread which is not then manloop thread
of SWT) must  do a
Display.getDefault().syncExec(new Modifier());

by

Le 10 mars 2012 07:16, ashbb <ashbbb@gmail.com> a écrit :

> Hi all,
>
> I have a question about a small snippet written in JRuby and SWT.
>
> Try out this snippet: https://gist.github.com/2010465
>
> This snippet works. A red rectangle will appear on a window.
> But, after deleting number sign `#`s , I mean using `Thread`, nothing
> appear.
>
> Why??
>
> ashbb
>
>


-- 

- - - - - - - - - - - - - - - - -
 __   ___  __   .  __
|__) |__  / _`  | /__`
|  \ |___ \__> L| .__/

http://regisaubarede.posterous.com/
- - - - - - - - - - - - - - - - -

Re: [shoes] Question about Thread in JRuby and SWT

From:
Peter Fitzgibbons
Date:
2012-03-15 @ 17:01
HI Régis,

For me who needs to be "in the know",

>> Display.getDefault().syncExec(new Modifier());
What does that line do, or return?

Thanks,
Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com

Re: [shoes] Question about Thread in JRuby and SWT

From:
Régis d'Aubarède
Date:
2012-03-15 @ 21:44
Modifier is a Runnable class,  which contain one method, 'run()'.
So, (in java), you must code your SWT  instruction in a run() method of a
specialized class, and
 give it to Display, which will  transmit this object to the mainloop in
main thread for calling his run() method in the context of mainloop.


in green shoes, you can do the same with :

invoke_in_shoes_mainloop   { shoes code }


sorry for my English...



Le 15 mars 2012 18:01, Peter Fitzgibbons <peter.fitzgibbons@gmail.com> a
écrit :

> HI Régis,
>
> For me who needs to be "in the know",
>
> >> Display.getDefault().syncExec(new Modifier());
> What does that line do, or return?
>
> Thanks,
> Peter Fitzgibbons
> (847) 859-9550
> Email: peter.fitzgibbons@gmail.com
> IM GTalk: peter.fitzgibbons
> IM AOL: peter.fitzgibbons@gmail.com
>
>


-- 

- - - - - - - - - - - - - - - - -
 __   ___  __   .  __
|__) |__  / _`  | /__`
|  \ |___ \__> L| .__/

http://regisaubarede.posterous.com/
- - - - - - - - - - - - - - - - -

Re: [shoes] Question about Thread in JRuby and SWT

From:
ashbb
Date:
2012-03-16 @ 12:40
Hi Régis and Peter,

The following two work as well. :)

# ex.1
class A
  def initialize &blk
    @blk = blk
  end
  def run
    @blk.call
  end
end
a = A.new{puts 'hello'}
Display.getDefault.asyncExec a

# ex.2
Display.getDefault.asyncExec{puts 'hello'}

ashbb

Re: [shoes] Question about Thread in JRuby and SWT

From:
ashbb
Date:
2012-03-15 @ 13:08
Hi Régis,

> SWT is not thread safe.
> In java, threaded code (ie code in thread which is not then manloop
thread of
> SWT) must  do a Display.getDefault().syncExec(new Modifier());
Aha, I got it. I'll check it out.

Thanks for the information. :)

ashbb