Jump to page: 1 25  
Page
Thread overview
Oh, my GoD! Goroutines on D
Mar 27, 2016
Jin
Mar 27, 2016
deadalnix
Mar 27, 2016
Walter Bright
Mar 28, 2016
Jin
Mar 28, 2016
Lass Safin
Mar 28, 2016
Russel Winder
Mar 28, 2016
Walter Bright
Mar 28, 2016
Jin
Mar 29, 2016
Walter Bright
Mar 29, 2016
Walter Bright
Mar 29, 2016
sigod
Mar 28, 2016
Jacob Carlborg
Mar 28, 2016
Ali Çehreli
Mar 29, 2016
Jacob Carlborg
Mar 29, 2016
Dejan Lekic
Mar 29, 2016
Jin
Mar 29, 2016
H. S. Teoh
May 16, 2020
mw
May 17, 2020
Russel Winder
May 18, 2020
Andre Pany
May 19, 2020
Seb
May 19, 2020
Russel Winder
May 25, 2020
Jin
Jun 14, 2020
mw
May 19, 2020
Bienlein
May 19, 2020
Panke
May 19, 2020
Russel Winder
May 25, 2020
Jin
May 26, 2020
Mathias LANG
May 26, 2020
Johannes Loher
May 26, 2020
Russel Winder
Jun 14, 2020
mw
Jun 14, 2020
mw
Jun 14, 2020
Jin
Jun 14, 2020
mw
Jun 15, 2020
mw
Jun 15, 2020
Jin
Jun 15, 2020
mw
Jun 14, 2020
Jin
Jun 14, 2020
mw
Mar 30, 2016
Casey Sybrandy
Mar 30, 2016
Casey Sybrandy
Mar 30, 2016
Jin
Mar 30, 2016
Casey Sybrandy
Apr 01, 2016
Russel Winder
Apr 01, 2016
Russel Winder
March 27, 2016
DUB module: http://code.dlang.org/packages/jin-go
GIT repo: https://github.com/nin-jin/go.d

Function "go" starts coroutines (vibe.d tasks) in thread pool like in Go language:

	unittest
	{
		import core.time;
		import jin.go;

		__gshared static string[] log;

		static void saying( string message )
		{
			for( int i = 0 ; i < 3 ; ++i ) {
				sleep( 100.msecs );
				log ~= message;
			}
		}

		go!saying( "hello" );
		sleep( 50.msecs );
		saying( "world" );

		log.assertEq([ "hello" , "world" , "hello" , "world" , "hello" , "world" ]);
	}

Class "Channel" is wait-free one-consumer-one-provider channel. By default, Channel blocks thread on receive from clear channel or send to full channel:

unittest
{
	static void summing( Channel!int output ) {
		foreach( i ; ( output.size * 2 ).iota ) {
			output.next = 1;
		}
		output.close();
	}

	auto input = go!summing;
	while( !input.full ) yield;

	input.sum.assertEq( input.size * 2 );
}

You can no wait if you do not want:

	unittest
	{
		import core.time;
		import jin.go;

		static auto after( Channel!bool channel , Duration dur )
		{
			sleep( dur );
			if( !channel.closed ) channel.next = true;
		}

		static auto tick( Channel!bool channel , Duration dur )
		{
			while( !channel.closed ) after( channel , dur );
		}

		auto ticks = go!tick( 101.msecs );
		auto booms = go!after( 501.msecs );

		string log;

		while( booms.clear )
		{
			while( !ticks.clear ) {
				log ~= "tick";
				ticks.popFront;
			}
			log ~= ".";
			sleep( 51.msecs );
		}
		log ~= "BOOM!";

		log.assertEq( "..tick..tick..tick..tick..BOOM!" );
	}

Channel are InputRange and OutputRange compatible. Structs "Inputs" and "Outputs" are round-robin facade to array of channels.

More examples in unit tests: https://github.com/nin-jin/go.d/blob/master/source/jin/go.d#L293

Current problems:

1. You can give channel to more than two thread. I'm going to play with unique pointers to solve this problem. Any hints?

2. Sometimes you must close channel to notify partner to break range cycle. Solving (1) problem can solve and this.

3. API may be better. Advices?
March 27, 2016
On Sunday, 27 March 2016 at 18:17:55 UTC, Jin wrote:
> 1. You can give channel to more than two thread. I'm going to play with unique pointers to solve this problem. Any hints?
>

Note that this is also the case in go. Yes, contrary to what is usually said, go is dead usnafe when it come to threads.

March 27, 2016
On 3/27/2016 11:17 AM, Jin wrote:
> [...]

Nice! Please write an article about this!

March 28, 2016
On 2016-03-27 20:17, Jin wrote:
> DUB module: http://code.dlang.org/packages/jin-go
> GIT repo: https://github.com/nin-jin/go.d
>
> Function "go" starts coroutines (vibe.d tasks) in thread pool like in Go
> language:

It would be useful with a wiki page, or similar, that describes and compares different ways of doing concurrency in D, both built-in and third party libraries like this and vibe.d. Also compare against other languages like Go, Erlang, Scala and so on.

-- 
/Jacob Carlborg
March 28, 2016
On Sunday, 27 March 2016 at 20:39:57 UTC, Walter Bright wrote:
> On 3/27/2016 11:17 AM, Jin wrote:
>> [...]
>
> Nice! Please write an article about this!

My english is too bad to write articles, sorry :-(
March 28, 2016
On Monday, 28 March 2016 at 13:10:45 UTC, Jin wrote:
> On Sunday, 27 March 2016 at 20:39:57 UTC, Walter Bright wrote:
>> On 3/27/2016 11:17 AM, Jin wrote:
>>> [...]
>>
>> Nice! Please write an article about this!
>
> My english is too bad to write articles, sorry :-(

Just use engrish, we won't care. Really.
March 28, 2016
On Mon, 2016-03-28 at 13:10 +0000, Jin via Digitalmars-d wrote:
>
> My english is too bad to write articles, sorry :-(

Write the article content and then get someone who is a person good at writing in English to ghostwrite the article from your content.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



March 28, 2016
On 3/28/2016 6:10 AM, Jin wrote:
> My english is too bad to write articles, sorry :-(

Baloney, your english is very good. Besides, I'm sure there will be many volunteers here to help you touch it up.
March 28, 2016
On Monday, 28 March 2016 at 19:29:55 UTC, Walter Bright wrote:
> On 3/28/2016 6:10 AM, Jin wrote:
>> My english is too bad to write articles, sorry :-(
>
> Baloney, your english is very good. Besides, I'm sure there will be many volunteers here to help you touch it up.

I just wrote the article on russin: https://habrahabr.ru/post/280378/
Translation to english: https://translate.google.com/translate?hl=ru&sl=ru&tl=en&u=https%3A%2F%2Fhabrahabr.ru%2Fpost%2F280378%2F
March 28, 2016
On 03/28/2016 03:49 AM, Jacob Carlborg wrote:
> On 2016-03-27 20:17, Jin wrote:
>> DUB module: http://code.dlang.org/packages/jin-go
>> GIT repo: https://github.com/nin-jin/go.d
>>
>> Function "go" starts coroutines (vibe.d tasks) in thread pool like in Go
>> language:
>
> It would be useful with a wiki page, or similar, that describes and
> compares different ways of doing concurrency in D, both built-in and
> third party libraries like this and vibe.d. Also compare against other
> languages like Go, Erlang, Scala and so on.
>

And make sure to tell me about it so that my DConf presentation will be more complete: :)

  http://dconf.org/2016/talks/cehreli.html

That abstract is awfully short but I've posted a pull request to improve it a little bit:

<quote>
D provides support for multitasking in the form of language features and standard library modules. D makes it easy for your programs to perform multiple tasks at the same time. This kind of support is especially important in order to take advantage of the multiple CPU cores that are available on modern computing systems.

Multitasking is one of the most difficult computing concepts to implement correctly. This talk will introduce different kinds of multitasking, as well as parallelism, a concept which is in fact unrelated to, but is often confused with, multitasking. The talk will conclude with fibers (aka co-routines), a powerful tool that is often overlooked despite its convenience.
</quote>

Seriously, I appreciate any documentation links that you can give to complete my "homework" before DConf. :)

Ali

« First   ‹ Prev
1 2 3 4 5