Re: GCD code in plain old C, and a correctness question
Re: GCD code in plain old C, and a correctness question
- Subject: Re: GCD code in plain old C, and a correctness question
- From: Kevin Van Vechten <email@hidden>
- Date: Tue, 08 Sep 2009 00:05:52 -0700
On Sep 7, 2009, at 7:56 PM, David Leimbach wrote: Aside from having to bump up my file descriptors to run this code, I'm not sure why I'm getting "????" at the end of the code linked here:
Otherwise it appears to function properly.
I'm basically writing a concurrent prime number sieve using libdispatch data structures, and using pipe fds to sort of simulate an "actor message passing style" by tying together event sources on the read end of a pipe pair of fds. Since none of the sources or contexts know when the computation is complete by the amount of data they've received, I send a -1 through the entire sieve of blocks to cause shutdown to occur. ) If you look at my earlier versions of this code, I was using a sleep call). Even this new version of the code seems to function up until the "????".
I'm trying to decide if this is a bug on my part or not.
Also, running this without bumping the ulimit for fds caused my Snow Leopard machine to kernel panic just once. So if you run this, please do so with that caveat. I've been as of yet unable to reproduce this crash, but I'll file a bug report if I do.
I believe the "????" is the result of writing (int)-1 to stdout.
When setup_block() is called on a read_fd that has a pending -1, then the else clause of if (val !+ LAST) in the event handler will be executed. This writes -1 to fd 0 (stdout) because the ctx structure was never initialized beyond the initial calloc.
Is my understanding correct that each fd source represents a stage in a pipeline with a corresponding integer (the first value read off the pipe) and only numbers not divisible by the current number are allow to pass further down the pipeline?
Have you considered the same design using only dispatch queues? That would avoid the file descriptor limit you're hitting. Instead of writing integers to pipes, you could simply dispatch_async() the integer to the next queue in the "pipeline." Submitting a block object to a queue is a form of message passing.
Kevin |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden