[ruby-trunk - Bug #6694][Open] Thread.new without block

Issue #6694 has been updated by uggbootsstore (uggbootsstore
uggbootsstore).

=begin
those who live in or have lived in the shadow ((<Uggs On
Sale|URL:http://www.uggbootsstore.biz/>)) of death no matter what would
be happy. However, most of us think of your <((<uggs
outlet|URL:http://www.uggbootsstore.biz/>)) life as the behoove. We know
that one day we must die, but usually we picture that day as far
((<Cheap Ugg Boots|URL:http://www.uggbootsstore.biz/>)) in the future.
When we are in buoyant health, death is all but unimaginable, we seldom
think of it. There seems no end date. 458gyu854
=end

Feature #6694: Thread.new without block.
https://bugs.ruby-lang.org/issues/6694#change-33578

Author: ko1 (Koichi Sasada)
Status: Assigned
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: next minor

=begin
= Abstract

Support Thread.new() without block.

Before: Thread.new(params…){|thread_local_params| …}

After: Thread.new(proc: lambda{|tl_params…| …}, args: params…,
other_thread_config…)

= Background

Thread.new creates new Thread object and run passed block in another
thread immediately. Thread.new can receive parameters and pass all
parameters to block.

Thread.new(a, b, c) do |ta, tb, tc|
# ta, tb, tc is thread local
}

There are some request to specify thread configurations such as stack
size described in [Ruby 1.9 - Feature #3187] (in this case, stack size
for Fiber.new). However, we have no way to pass such thread
configuration on the Thread.new().

= Proposal

Allow Thread.new() without block. A block will be passed with proc
parameter. Passed arguments will be passed with args parameter.

ex1

Thread.new(){…}
#=>
Thread.new(proc: -> {…})

ex2

Thread.new(a, b, c){|ta, tb, tc| …}
#=>
Thread.new(proc: ->(ta, tb, tc){ … }, params: [a, b, c])

If you want to specify stack size, then:

Thread.new(stack_size: 4096, proc: proc{…}, args: [a, b, c])

Note that I’ll make another ticket for thread (and fiber) creation
parameters.

This change can be described with the following pseudo code:

def Thread.new(*args, &block)
if block
Thread.new_orig(*args, &block)
else
config = args[0] || raise ArgumentError
stack_size = config[:stack_size]
# … and process another parameters
Thread.new_orig(*config[:args], &config[:proc])
end
end

= Another proposal

On the [ruby-core:43385], Nahi-san proposed that if no block given on
Thread.new(), then create “waiting” thread. Thread#run kicks waiting
thread with parameters.

th = Thread.new(thread_config_params)

th.run(params){|thread_local_params|

}

We can combine with proc: parameter and this proposal. If Thread.new()
doesn’t have block and proc: parameter, then making a waiting thread.

NOTE: Because we have already Thread#run, Thread#start is better than
Thread#run?

= Note

I don’t make any survey on other languages. Please give us your
comments.

=end

Issue #6694 has been updated by ueggsmarketing (ueggsmarketing
ueggsmarketing).

=begin
limited to the. Such stories set us thinking, ((<cheap ugg
boots|URL:http://www.ueggsmarketing.net/>)) in similar circumstances,
what should we do? As mortal beings, in the last several hours we ought
to do something, to ((<ugg boots on
sale|URL:http://www.ueggsmarketing.net/>)) experience what associations?
The memories of the past, what makes us happy? What makes us regret?
Sometimes I think, regard every day as the last day in the life to
come.458gyu854
=end

Feature #6694: Thread.new without block.
https://bugs.ruby-lang.org/issues/6694#change-33615

Author: ko1 (Koichi Sasada)
Status: Assigned
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: next minor

=begin
= Abstract

Support Thread.new() without block.

Before: Thread.new(params…){|thread_local_params| …}

After: Thread.new(proc: lambda{|tl_params…| …}, args: params…,
other_thread_config…)

= Background

Thread.new creates new Thread object and run passed block in another
thread immediately. Thread.new can receive parameters and pass all
parameters to block.

Thread.new(a, b, c) do |ta, tb, tc|
# ta, tb, tc is thread local
}

There are some request to specify thread configurations such as stack
size described in [Ruby 1.9 - Feature #3187] (in this case, stack size
for Fiber.new). However, we have no way to pass such thread
configuration on the Thread.new().

= Proposal

Allow Thread.new() without block. A block will be passed with proc
parameter. Passed arguments will be passed with args parameter.

ex1

Thread.new(){…}
#=>
Thread.new(proc: -> {…})

ex2

Thread.new(a, b, c){|ta, tb, tc| …}
#=>
Thread.new(proc: ->(ta, tb, tc){ … }, params: [a, b, c])

If you want to specify stack size, then:

Thread.new(stack_size: 4096, proc: proc{…}, args: [a, b, c])

Note that I’ll make another ticket for thread (and fiber) creation
parameters.

This change can be described with the following pseudo code:

def Thread.new(*args, &block)
if block
Thread.new_orig(*args, &block)
else
config = args[0] || raise ArgumentError
stack_size = config[:stack_size]
# … and process another parameters
Thread.new_orig(*config[:args], &config[:proc])
end
end

= Another proposal

On the [ruby-core:43385], Nahi-san proposed that if no block given on
Thread.new(), then create “waiting” thread. Thread#run kicks waiting
thread with parameters.

th = Thread.new(thread_config_params)

th.run(params){|thread_local_params|

}

We can combine with proc: parameter and this proposal. If Thread.new()
doesn’t have block and proc: parameter, then making a waiting thread.

NOTE: Because we have already Thread#run, Thread#start is better than
Thread#run?

= Note

I don’t make any survey on other languages. Please give us your
comments.

=end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs