Scala Queue implementation that is parallel/thread safe? -
i have implementation of linked queue in scala, not parallel-safe. i'm not sure changes need make make implementation parallel-safe…any suggestions?
class linkedqueue[a] extends queue[a] { private class node (var data:a, var next:node) private var head:node = null private var last:node = null def isempty():boolean = head == null def peek():a = { assert(head != null) head.data } def dequeue():a = { assert(head != null) val ret = head.data head = head.next if(head == null) last = head ret } def enqueue(elem:a) { if(last == null) { head = new node(elem, null) last = head } else { last.next = new node(elem, null) last = last.next } } }
Comments
Post a Comment