Project

General

Profile

Feature #8919

Queue as embedded class

Added by ko1 (Koichi Sasada) about 4 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:57256]

Description

Queue class in lib/thread.rb (ext/thread/thread.c from Ruby 2.1) is easy and safe way to communicate between threads.

How about to include Queue class as embedded class to elaborate using Queue?

This proposal is not include ConditionVariable and SizedQueue.

patch.diff (15.7 KB) patch.diff Queue Implementation as embedded class Glass_saga (Masaki Matsushita), 11/27/2014 12:30 AM

Associated revisions

Revision 51660
Added by ko1 (Koichi Sasada) over 2 years ago

  • ext/thread/thread.c: move definitions of Queue, SizedQueue and ConditionalVariables to thread_tools.c. In other wowrds, such classes are built-in. [Feature #8919] At first, I planned to embed only a Queue class. However, rubygems requires 'thread.rb' (rubygems are required at first, when launch MRI without --disable-gems). So most of people require 'thread.rb' as an embedded library. Now, ext/thread/thread.c is empty, only for a dummy for compatibility.
  • thread.c: move a definition of Mutex class to thread_tools.c. And define Mutex class under Thread (so now Mutex is Thread::Mutex). Because other thread related classes are also defined under Thread. We remain ::Mutex as Thread::Mutex. Only an inspect result is changed.
  • common.mk: add dependency from thread.o to thraed_tools.c.

Revision 51660
Added by ko1 (Koichi Sasada) over 2 years ago

  • ext/thread/thread.c: move definitions of Queue, SizedQueue and ConditionalVariables to thread_tools.c. In other wowrds, such classes are built-in. [Feature #8919] At first, I planned to embed only a Queue class. However, rubygems requires 'thread.rb' (rubygems are required at first, when launch MRI without --disable-gems). So most of people require 'thread.rb' as an embedded library. Now, ext/thread/thread.c is empty, only for a dummy for compatibility.
  • thread.c: move a definition of Mutex class to thread_tools.c. And define Mutex class under Thread (so now Mutex is Thread::Mutex). Because other thread related classes are also defined under Thread. We remain ::Mutex as Thread::Mutex. Only an inspect result is changed.
  • common.mk: add dependency from thread.o to thraed_tools.c.

Revision 51660
Added by ko1 (Koichi Sasada) over 2 years ago

  • ext/thread/thread.c: move definitions of Queue, SizedQueue and ConditionalVariables to thread_tools.c. In other wowrds, such classes are built-in. [Feature #8919] At first, I planned to embed only a Queue class. However, rubygems requires 'thread.rb' (rubygems are required at first, when launch MRI without --disable-gems). So most of people require 'thread.rb' as an embedded library. Now, ext/thread/thread.c is empty, only for a dummy for compatibility.
  • thread.c: move a definition of Mutex class to thread_tools.c. And define Mutex class under Thread (so now Mutex is Thread::Mutex). Because other thread related classes are also defined under Thread. We remain ::Mutex as Thread::Mutex. Only an inspect result is changed.
  • common.mk: add dependency from thread.o to thraed_tools.c.

History

#1 [ruby-core:57538] Updated by ko1 (Koichi Sasada) about 4 years ago

Matz, how about it?

(no compatibility issue, we have an implementation)

#2 [ruby-core:60311] Updated by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • Target version changed from 2.1.0 to 2.2.0

#3 [ruby-core:60725] Updated by matz (Yukihiro Matsumoto) almost 4 years ago

It's OK for 2.2.

Matz.

#4 [ruby-core:64326] Updated by hsbt (Hiroshi SHIBATA) over 3 years ago

  • Status changed from Open to Assigned
  • Assignee changed from matz (Yukihiro Matsumoto) to ko1 (Koichi Sasada)

#5 [ruby-core:66502] Updated by Glass_saga (Masaki Matsushita) almost 3 years ago

How about the implementation in attached patch.diff?

#6 [ruby-core:66507] Updated by ko1 (Koichi Sasada) almost 3 years ago

Now, thread.rb is required from rubygems.

$ ./ruby -ve 'p Queue'
ruby 2.2.0dev (2014-11-20 trunk 48507) [x86_64-linux]
Thread::Queue

and

$ ./ruby --disable-gems -ve 'p Queue'
ruby 2.2.0dev (2014-11-20 trunk 48507) [x86_64-linux]
-e:1:in `<main>': uninitialized constant Queue (NameError)

What should we do?

#7 [ruby-core:66536] Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

By adding a line thread to ext/Setup file, thread.so can be statically linked to ruby (or libruby) now.

#8 Updated by ko1 (Koichi Sasada) over 2 years ago

  • Status changed from Assigned to Closed

Applied in changeset r51660.


  • ext/thread/thread.c: move definitions of Queue, SizedQueue and ConditionalVariables to thread_tools.c. In other wowrds, such classes are built-in. [Feature #8919] At first, I planned to embed only a Queue class. However, rubygems requires 'thread.rb' (rubygems are required at first, when launch MRI without --disable-gems). So most of people require 'thread.rb' as an embedded library. Now, ext/thread/thread.c is empty, only for a dummy for compatibility.
  • thread.c: move a definition of Mutex class to thread_tools.c. And define Mutex class under Thread (so now Mutex is Thread::Mutex). Because other thread related classes are also defined under Thread. We remain ::Mutex as Thread::Mutex. Only an inspect result is changed.
  • common.mk: add dependency from thread.o to thraed_tools.c.

Also available in: Atom PDF