• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Help.....Thread

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Can anyone explain me the output of the program.....

Thanks in advance.
Aruna
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
both treads increment i,k, and j in each of eternal loop invocation and return equal values.
so letters printed if workWithoutLocks( ) executed between first and second variables increment , and it is possible without any legimitacy.
see example 9.6 Mugal and Pasmussen
cheers
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aruna,
I can't predict the result.Itz displaying infinite 'j' thatz right but some time it displays i & k also.I don't know why?.Lets wait for others to answer.
Shalini
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aru,
The code that u have posted started printing k,j.........and so
on ...it prints the same witout stopping ...infinitely....
Wonder why it does that !
Prav
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the line if (j1 != j2) System.out.println("j");
with if (j1 != j2) System.out.println(j1+"j"+j2);
and found that the condition j1 != j2 is true after going through several loops ..
It seems that after sometime one thread lags behind the other one
 
reply
    Bookmark Topic Watch Topic
  • New Topic