<div class="gmail_quote">On 20 January 2012 00:36, Sean Kelly <span dir="ltr"><<a href="mailto:sean@invisibleduck.org">sean@invisibleduck.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks :-)  If you have ideas on how it could be improved, please let me know.<br>
<div class="HOEnZb"><div class="h5"><br>
On Jan 19, 2012, at 12:58 PM, Nathan M. Swan wrote:<br>
<br>
> I want to applaud Sean Kelly and everyone who worked on std.concurrency for a great API, and wish that I could easily write Cocoa applications with it.<br>
><br>
> I'm writing a screen recording program in Objective-C, and to make sure each frame has an equal length, I have two threads: one that takes the screenshot at certain intervals, the other that assembles it into a quicktime movie. After writing an implementation of a thread-safe queue, where the picture-taking thread adds and the assembling thread removes, I realized the huge similarity between what I'd done and std.concurrency.<br>

><br>
> The std.concurrency module would have made hours of effort in ObjC take five minutes in D. Well done!<br></div></div></blockquote><div><br></div><div>I had some troubles with std.concurrency which I thought it might be nice to address.</div>
<div><br></div><div>Perhaps the most major problem I had was related to the concept of thread ownership. If a spawned threads parent thread dies, it also receives a signal to kill its self, but it seems impossible to reassign ownership.</div>
<div>In my case I had threads A, B and C...</div><div>  Thread A is the main thread, which may spawn many temporary worker threads B, which may last 1-2 seconds.</div><div>  During the life of B, it may spawn C, which may persist for hours.</div>
<div>  B promptly dies, and any C's that were spawned receive the kill signal, which I ignore.</div><div>  Thread A, the main thread may exit, and I would really like all C's to receive that notification, but they were are all orphaned when their B died.</div>
<div>The problem is, when I spawn a C, it should be created as a child of A somehow, rather than a child of the transient B... Some mechanism to solve this sort of problem would be useful.</div><div><br></div><div>Another usability problem I had was that, intuitively, the simpler function with intuitive usage pattern receiveOnly() should be named receive().</div>
<div>And receive() with the complex var-arg list of delegates should be named something more complex.</div><div>receiveTimeout() has no receiveTimeoutOnly(), which is the function I almost always want to use... and receiveTimeout() didn't actually work for me anyway (it wouldn't receive a duration as per the documentation, I had to pass an int)</div>
<div><br></div><div>I wonder if there is a solution to the 'shared' problem. Basically every single line of code that uses the std.concurrenty api is riddled with casts to/from shared... really ugly.</div><div>I think the problem here is that I'm not SHARING values between threads, I'm actually passing ownership of something to another thread. So I wonder if some improvement can be made in this area.</div>
<div><br></div><div>I was going to complain about the documentation, but I just checked, and it seems to have had work since I was reading it. Looks much better now! :)</div></div>