George
04/06/2023, 12:55 PMprivate class Node(
val job: QueueJob,
// Pointer to the next node in linked list.
val next: AtomicRef<Node?> = atomic(null)
) {
// Checks if this node is the physical tail of the linked list.
val isTail: Boolean get() = next.value == null
}
Error:
Exception in thread "main" java.lang.NoSuchMethodError: 'void asynqueueproblem.Queue$Node.<init>(kotlin.jvm.functions.Function2, kotlinx.atomicfu.AtomicRef, int, kotlin.jvm.internal.DefaultConstructorMarker)'
at asynqueueproblem.Queue.<init>(Queue.kt:40)
at asynqueueproblem.Queue.<init>(Queue.kt:13)
at asynqueueproblem.QueueKt.queueWithInitialValue(Queue.kt:116)
at asynqueueproblem.MainKt$main$1.invokeSuspend(Main.kt:12)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at asynqueueproblem.MainKt.main(Main.kt:11)
at asynqueueproblem.MainKt.main(Main.kt)
Complete code can be found here: https://github.com/GeorgePap-719/asyn-request-queue-problem/blob/main/src/main/kotlin/Queue.kt
It complains when i am creating an instance of Node
.George
04/06/2023, 12:56 PMNode
to something like this:
private class Node(
val job: QueueJob,
@Suppress("LocalVariableName") _next: Node? = null
) {
// Pointer to the next node in linked list.
val next: AtomicRef<Node?> = atomic(_next)
// Checks if this node is the physical tail of the linked list.
val isTail: Boolean get() = next.value == null
fun setNext(newNode: Node) {
while (true) if (next.compareAndSet(null, newNode)) return
}
}
The error goes away.