Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

bind?

Moderators: larsivi kris

Posted: 07/26/07 15:31:34

As I understand it, the inclusion of bind into tango is up in the air. Candidate implementations exist (according to Sean Kelly, I should be asking h3r3tic for it).

I'll dedicate this post to giving a description of my use case. I have a multi-threaded application where I'm using function objects (void delegate()) as a generalized method for passing commands between threads. The commands are really nothing more deferred function calls. Because the function calls can change thread state/behavior, random asynchronous changes can really wreak havoc on code operation. To get around this, function calls are deferred until a stable thread state is reached. I've created a queue within each thread for storing commands to be processed.

In 90% of the cases, this works great:

thread.insert(&thread.doSomething); thread.insert( {thread.setWidgetCount(5);} ); etc...

Other times, it breaks down. For example:

foreach(foo;bar) thread.insert( {thread.someAction(foo);} );

Here, the local variable foo may get overridden or go completely out of scope before the command is processed.

Author Message

Posted: 07/27/07 11:33:41

FWIW, it looks like you're trying to emulate a stack, to some degree? Have you though about using Fibers instead?