Files
kotlin-fork/stdlib/ktSrc/Thread.kt
T
Andrey Breslav 4579c9826f Reverting problematic commits:
fa500f453d	Alex Tkachman	Today 19:47
725bebc23f	Alex Tkachman	Today 19:36
2011-12-27 21:26:20 +04:00

42 lines
1.1 KiB
Kotlin

package 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: ()->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
}