Thread.kt

This commit is contained in:
Alex Tkachman
2011-12-19 15:55:00 +02:00
parent 1e471aa9c4
commit 2ae3e9e6c6
+41
View File
@@ -0,0 +1,41 @@
namespace std.concurrent
import java.lang.*
inline var Thread.name : String
get() = getName().sure()
set(name: String) { setName(name) }
inline var Thread.daemon : Boolean
get() = isDaemon()
set(on: Boolean) { setDaemon(on) }
inline val Thread.alive : Boolean
get() = isAlive()
inline var Thread.priority : Int
get() = getPriority()
set(prio: Int) { setPriority(prio) }
inline var Thread.contextClassLoader : ClassLoader?
get() = getContextClassLoader()
set(loader: ClassLoader?) { setContextClassLoader(loader) }
fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: fun():Unit) : Thread {
val thread = object: Thread() {
override fun run() {
block()
}
}
if(daemon)
thread.setDaemon(true)
if(priority > 0)
thread.setPriority(priority)
if(name != null)
thread.setName(name)
if(contextClassLoader != null)
thread.setContextClassLoader(contextClassLoader)
if(start)
thread.start()
return thread
}