@Ankuj: Sorry. I read the getch() as a call to green().
Please ignore the 20 green(). It should be 10 green() instead.
--
DK
http://twitter.com/divyekapoor
http://www.divye.in
http://gplus.to/divyekapoor
--
You received this message because you are subscribed to the Google Groups
"Algorithm
6 red 10 greens
On Wed, Aug 24, 2011 at 9:25 AM, Ankuj Gupta wrote:
> how can be there 20 greens ?
>
> On Aug 24, 12:12 am, DK wrote:
> > The standard library is neither multithread safe nor multiprocess safe.
> > If you want the correct answer, use shared memory and maintain a shared
> > cou
how can be there 20 greens ?
On Aug 24, 12:12 am, DK wrote:
> The standard library is neither multithread safe nor multiprocess safe.
> If you want the correct answer, use shared memory and maintain a shared
> counter. Alternatively, as a quick hack, insert a fflush(stdout) after the
> printf sta
The standard library is neither multithread safe nor multiprocess safe.
If you want the correct answer, use shared memory and maintain a shared
counter. Alternatively, as a quick hack, insert a fflush(stdout) after the
printf statements.
Answer:
red() - 6
green() - 20
--
DK
http://twitter.
I Can See 10 Green and 10 Red Process.. Can Someone Compile to verify
this...
Prem
On Tue, Aug 23, 2011 at 1:24 AM, gmagog...@gmail.com wrote:
> Infinite times
> Yanan Cao
>
>
>
> On Mon, Aug 22, 2011 at 2:43 PM, Don wrote:
>
>> // DO NOT RUN THIS! By inspection, how many times will it print "H
Infinite times
Yanan Cao
On Mon, Aug 22, 2011 at 2:43 PM, Don wrote:
> // DO NOT RUN THIS! By inspection, how many times will it print "Hello
> world"?
> // If you find out by running it, that is cheating. Don't do it!
> int main()
> {
> int i=0, j=0;
> for(i = 0; i*j < 20; ++i)
> {
>if
I am getting 6 red and 8 green as expected using the original code
Yanan Cao
On Mon, Aug 22, 2011 at 2:38 PM, Yasir wrote:
> Surprisingly, if I comment the last if condition ( which is AFTER red()
> call ), it is printing red only 6 times as expected..
> http://ideone.com/XMHzC
>
> main()
> {
// DO NOT RUN THIS! By inspection, how many times will it print "Hello
world"?
// If you find out by running it, that is cheating. Don't do it!
int main()
{
int i=0, j=0;
for(i = 0; i*j < 20; ++i)
{
if (fork() > 0) ++j;
else i = j = 0;
printf("Hello world\n");
}
return 0;
}
Surprisingly, if I comment the last if condition ( which is AFTER red() call
), it is printing red only 6 times as expected.. http://ideone.com/XMHzC
main()
{
fork();
int color=fork();
if(color==0)
fork();
red();
//if(color==0)
// fork
I am getting 6 calls to red and 8 calls to green when i built parent
child tree but when i ran this code
http://ideone.com/UBaBB
I got 10 calls to red and 10 calls to green.
Can some explain this ?
On Aug 22, 9:31 pm, ghsjgl k wrote:
> i saw this question in one of DREAM companies
>
> i dont kn
10 matches
Mail list logo