[Bug 55] New: Cflow is not propagated properly across multiple threads

From: <abc-bugs@comlab.ox.ac.uk>
Date: Thu Aug 04 2005 - 16:50:56 BST

http://abc.comlab.ox.ac.uk/cgi-bin/bugzilla/show_bug.cgi?id=55

           Summary: Cflow is not propagated properly across multiple threads
           Product: abc
           Version: 1.0.2
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: AspectJ compiler
        AssignedTo: abc-bugs@comlab.ox.ac.uk
        ReportedBy: bruno.harbulot@cs.man.ac.uk

The state of the cflow counter does not work properly across several threads.

Here is a simple example:

public class Test {
        public void run(int counter) {
                System.out.println("Thread: "+Thread.currentThread().hashCode()+", counter:
"+counter) ;
                if (counter>0) {
                        counter-- ;
                        run(counter) ;
                }
        }

        public static void main(String[] args) {
                Test t = new Test() ;
                t.run(2) ;
        }
}

public aspect Parallel {
        pointcut executerun(): execution(void Test.run(*)) ;
        pointcut outerexecuterun(): executerun() && !cflowbelow(executerun()) ;
        
        private final int THREADS_COUNT = 2 ;
        
        void around(): outerexecuterun() {
                System.out.println("Before outerexecuterun()") ;
                Thread[] threads = new Thread[THREADS_COUNT] ;
                for (int k = 0 ; k<THREADS_COUNT ; k++) {
                        threads[k] = new Thread(new Runnable() {
                                public void run() {
                                        proceed() ;
                                }
                        }) ;
                }
                
                try {
                        for (int k = 1 ; k<THREADS_COUNT ; k++) {
                                threads[k].start() ;
                        }
                        threads[0].run() ;
                        for (int k = 1 ; k<THREADS_COUNT ; k++) {
                                threads[k].join() ;
                        }
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
                
                System.out.println("After outerexecuterun()") ;
        }
}

The parallelisation aspect should only parallelise and duplicate the original
execution of run(int) for the execution that is not in the control-flow of an
execution of run(int).

The code generated with ajc (1.2.1) produces what is expected:

Before outerexecuterun()
Thread: 23065739, counter: 2
Thread: 23065739, counter: 1
Thread: 23065739, counter: 0
Thread: 11533424, counter: 2
Thread: 11533424, counter: 1
Thread: 11533424, counter: 0
After outerexecuterun()

The code generated with abc (1.0.2, with or without -abc101runtime) produces:
Before outerexecuterun()
Thread: 25358555, counter: 2
Thread: 25358555, counter: 1
Thread: 25358555, counter: 0
Thread: 26399554, counter: 2
Before outerexecuterun()
Thread: 26399554, counter: 1
Thread: 26399554, counter: 0
Thread: 7051261, counter: 1
Before outerexecuterun()
Thread: 7051261, counter: 0
Thread: 29855319, counter: 0
After outerexecuterun()
After outerexecuterun()
After outerexecuterun()

The !cflowbelow is not consider properly in the new thread generated by the advice.

A possible solution might consist of initialising the Counter in CFlowCounter to
the value of the counter as it is in the first generated counter (I guess using
the cached_thread value would also lead to problems, since the last thread
cached might not be the one in which the advice is executed.)

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
Received on Thu Aug 4 16:50:59 2005

This archive was generated by hypermail 2.1.8 : Thu Aug 04 2005 - 20:30:06 BST