-
Notifications
You must be signed in to change notification settings - Fork 62
Advanced tutorial "Encode Concurrency Blocks in RhoLang" #991
Comments
@golovach-ivan This is an interesting idea. I don't fully understand it, but I would like to. The same is true about some of your other projects. Can we get together for a call next week? I'm @JoshyOrndorff on discord, or you can answer here. |
@golovach-ivan contacted me via discord DM saying
Ivan, I am interested in learning more about this. But I won't sponsor it until I clearly understand it. When can you offer a walkthrough for me and others who may be interested like @David405 @dckc |
Issue basics: any language with implicit concurrency (RhoLang, Go, Java, etc) needs
Example: Ordered Message QueueIn Java for Ordered Message Queue between concurrent activities (threads) someone can
BlockingQueue backed by array based on explicit Monitor (Lock/Condition)
class BlockingQueue<T> {
private final Lock lock = new ReentrantLock();
private final Condition notFull = lock.newCondition();
private final Condition notEmpty = lock.newCondition();
private final int maxSize;
private final Queue<T> queue = new LinkedList<>();
public BlockingQueue(int maxSize) {
this.maxSize = maxSize;
}
public void put(T item) throws InterruptedException {
lock.lock();
try {
while (queue.size() == maxSize) {
notFull.await();
}
notEmpty.signal();
queue.add(item);
} finally {
lock.unlock();
}
}
public T take() throws InterruptedException {
lock.lock();
try {
while (queue.size() == 0) {
notEmpty.await();
}
notFull.signal();
return queue.remove();
} finally {
lock.unlock();
}
}
} Question: what should do RhoLang developer in this situation?I developer the aproach to systematically implement mutex as Cell pattern and conditional variables as blocked channel read and translate 10+ classes from java.util.concurrent to Rholang. In my opinion correct translation is
Issue home page = java.util.concurrent in Rholang |
One more interesting example: CountDownLatchIn Java (based on implicit Monitor)class CountDownLatch {
private int count;
public CountDownLatch(int count) {
this.count = count;
}
public synchronized void await() throws InterruptedException {
while (count != 0) { this.wait(); }
}
public synchronized void countDown() {
if (count == 1) { this.notifyAll(); }
if (count > 0) { count--; }
}
} In RhoLang
Complete source code for CountDownLatch (with demo)
|
Create tutorial specialized in concurrency.
Lets encode something "classic", widespread, popular, known to people.
Lets encode java.util.concurrent concurrency building blocks.
Plan A (good level)
{ Runnable, Callable, Future, Executor, AtomicInteger, Lock, Semaphore, LinkedBlockingQueue, CountDownLatch, Exchanger }.
Plan B (high level)
Plan A + { CompletableFuture, ReentrantLock, ReadWriteLock, ConcurrentMap, CyclicBarrier, Phaser }.
Benefit to RChain
Budget and Objective
Estimated Budget of Task: 3000$ for Plan A, 5000$ for Plan B.
Estimated Timeline Required to Complete the Task: 20-30 days
How will we measure completion? Plan A: 10 pages with described implementations + intro on GitHub (11 pages), Plan B: 15 pages with described implementations + intro on GitHub (16 pages).
The text was updated successfully, but these errors were encountered: