Re: concurrency driving me crazy



"Andersen" <andersen_800@xxxxxxxxxxx> schreef in bericht
news:439af00d$0$54384$892e7fe2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Boudewijn Dijkstra wrote:
>> A listing says more than a thousand words. May the source be with us?
>
> Certainly. Certain parts will be missing, but here it is. Search for *** to
> find the place where the problem occurs.
>
> [...]
>
> t1.start();
> t2.start();
> try {
> t1.join();
> t2.join();
> } catch (Exception ex) {
> ex.printStackTrace();
> }
>
> // *** This is were I get the fishy behaviour.
>
> System.out.println();
> long c1 = app1.getCount();
> long c2 = app2.getCount();
> assertEquals(c1, c2);
> assertEquals(c1, ROUTECOUNT);
> }
>
> [...]

Are you sure the final println isn't happening at the *beginning*?

When sending messages over sockets, they may pass through several threads
and/or processes before arriving at the destination. Because the messages are
passed asynchronously (=without waiting for it to get delivered), t1 and t2
will probably finish very quickly. So when the counts are queried, some
messages will still be queued somewhere and the assertion will fail.


.



Relevant Pages

  • Re: induction vs Cantor
    ... a listing is infinitely many relations between the naturals ... >> simple construction rule simultaneously defines for EVERY list of reals, ... >> ALL listings simultaneously that fail to be surjective. ... Since one can show that the set of reals is of the same cardinality as ...
    (sci.math)
  • Re: induction vs Cantor
    ... a listing is infinitely many relations between the naturals ... >> simple construction rule simultaneously defines for EVERY list of reals, ... >> ALL listings simultaneously that fail to be surjective. ... Since one can show that the set of reals is of the same cardinality as ...
    (sci.logic)
  • re:Combo Box Query
    ... appose to listing all 4 ... Regards, ... Oopesh ... Prev by Date: ...
    (microsoft.public.access.queries)
  • Deleting Entries in "By Most Visited"
    ... However the listing itself does not alway appear in Properties numeric ... Many thanks - CJB. ... Prev by Date: ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: check out this listing
    ... Neil ... > Check out this listing: ... > He knows what he wants and doesn't care about anything or anybody else. ... Prev by Date: ...
    (alt.marketing.online.ebay)