[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Platform Independence Programming

Patrick Hurley

7/11/2006 5:55:00 AM

On 7/11/06, Minkoo Seo <minkoo.seo@gmail.com> wrote:
> programs. That being the case, how can I rewrite the following program
> in platform independent way?
>
> print "Hello\r\n"

puts "Hello"

> Dir["/tmp/*"]

# note your code works fine under windows assuming you have a /tmp directory
tmp_path = ENV['TEMP'] || ENV['TMP'] || File.join('','tmp')
Dir[File.join(tmp_path,'*')]

> And I also wonder whether there's another problem related to platform
> independence.

Plenty :-), fork/process handling, services / daemons, drive
letters/mount points, IPC/pipes, etc. It really depends upon your
needs/goals many things are pretty easy, some are very difficult you
need to be more specific.

Good luck
pth

3 Answers

Patrick Hurley

7/11/2006 6:23:00 AM

0

On 7/11/06, Minkoo Seo <minkoo.seo@gmail.com> wrote:
> Thanks Patrick.
>
> I got one more question. The list you've shown doesn't contain threading.
> Is threading platform independent?
>

Ruby threads are pretty portable -- they are green and not OS, so they
do not have many gotchas. Now OS threads (which are not commonly or
easily used in Ruby programs) are a whole different issue.

pth

Dido Sevilla

7/11/2006 6:25:00 AM

0

On 7/11/06, Minkoo Seo <minkoo.seo@gmail.com> wrote:
> Thanks Patrick.
>
> I got one more question. The list you've shown doesn't contain threading.
> Is threading platform independent?

Current versions of Ruby work like what Java people call 'green'
threads, rather than using native threads; they'll work even if you're
running under one of those platforms that doesn't have support for
threading at all. There is code in the Ruby interpreter that simulates
a multithreaded environment without relying on any platform-specific
threading support.

Patrick Hurley

7/11/2006 6:43:00 AM

0

On 7/11/06, Minkoo Seo <minkoo.seo@gmail.com> wrote:
> What about priority of a Thread? Number of priorities vary from OS to OS,
> and it is said that priorities map to different prority levels depending on
> OS even
> if threads are green. How is Ruby's implementaion in this regard?

Ruby's threads have nothing really to do with OS threads -- they are
implemented entirely within the interpreter. Note that if you are on
multi-processor box, your app regardless of how many Ruby threads you
are using you will be only using one of them -- one process/one
thread. Priorities are also handled within the interpreter. You get
lucky here, not much to worry about.

pth