/***************************************************************************
 *   Copyright (C) by Fabrizio Montesi                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   For details about the authors of this software, see the AUTHORS file. *
 ***************************************************************************/

package jolie;

/**
 * A thread that can refer to its generating Interpreter.
 * @see Interpreter
 * @author Fabrizio Montesi
 */
abstract public class JolieThread extends Thread
{
	final private Interpreter interpreter;

	static private int counter = 0;
	static final private Object counterMutex = new Object();

	static private String createThreadName()
	{
		synchronized( counterMutex ) {
			return "JolieThread-" + counter++;
		}
	}
	
	public JolieThread( Interpreter interpreter, ThreadGroup threadGroup, String name )
	{
		super( threadGroup, interpreter.programFile().getName() + "-" + name );
		this.interpreter = interpreter;
	}
	
	public JolieThread( Interpreter interpreter )
	{
		super( interpreter.programFile().getName() + "-" + createThreadName() );
		this.interpreter = interpreter;
	}
	
	public JolieThread( Interpreter interpreter, Runnable r )
	{
		super( r, interpreter.programFile().getName() + "-" + createThreadName() );
		this.interpreter = interpreter;
	}
	
	/**
	 * Returns the interpreter that this thread refers to.
	 */
	public Interpreter interpreter()
	{
		return interpreter;
	}
}

@@ -1551,16 +1551,67 @@
 jolie;%0A%0A
+import java.util.concurrent.atomic.AtomicInteger;%0A%0A
 /**%0A * A
@@ -1816,24 +1816,30 @@
 %09static 
+final 
 private 
 int coun
@@ -1834,61 +1834,29 @@
 ate 
-int counter = 0;%0A%09static final private Object
+AtomicInteger
  counter
 Mute
@@ -1855,27 +1855,32 @@
 nter
-Mutex
  = new 
-Object(
+AtomicInteger( 0 
 );%0A%0A
@@ -1928,42 +1928,8 @@
 %0A%09%7B%0A
-%09%09synchronized( counterMutex ) %7B%0A%09
 %09%09re
@@ -1961,15 +1961,27 @@
 nter
-++;%0A%09%09%7D
+.getAndIncrement();
 %0A%09%7D%0A

Use AtomicInteger instead of a monitor.