Whoa, this is seriously cool. I will be checking this out in-depth.
Thanks a ton!
Bach
Whoa, this is seriously cool. I will be checking this out in-depth.
Thanks a ton!
Bach
These warnings should now also be fixed (copy & paste bug).
While debugging these a potential issue with the JavaAgent was discovered:
It is possible that multiple threads load classes at the same time, which also means that these thread execute instrumentClass in parallel.
I did not add a synchronization to that method (to prevent potential dead locks with ClassLoader locks) as MethodDatabase might need to load additional classes (eg the base class) - so instead I protected the shared hash maps individually.
This might cause redundant work (if multiple threads analyze the same class) - but each thread should produce the same results or a warning is generated.
So I suggest to use the JavaAgent only while developing - and keep an eye on the console for warning
It took a while to squash that bug, but together we persevered 8)
Version 0.8.5 has been released.
Download files
Iām writing to express my thoughts on how awesome this really is. This library opens up a whole new dimension for game logic writing. Iāll be adding this library into my engine very soon! (with credits of course!) ;D
Confirmed warnings are gone and it is still working as it should.
Just wanted to say that this works extremely well. Been implementing it into a little āprototypingā framework Iām building and Iām having a blast working with it.
Thanks heaps!
Bach
With two users (and counting) this is without a doubt my most successful library (wrapper)! 8)
Itās justā¦ Too high for meā¦ need to learn more scale / scheme (especially) or haskell firstā¦ Continuations? I just canāt deal with something like that right nao
Imagine that āreturnā is a function you call instead of some hardwired stack behavior. Thatās all a continuation is, the āreturnā function. The convention in languages that use a continuation passing style is that the compiler has the caller pass in the continuation. In CPS, you never pop the stack, you garbage collect it. Java doesnāt do any of this, so so a continuation library is essentially faking continuations as best it can.
You donāt need to know any of that to gain the benefits of green threads though.
Add me to the user list. It looks very interesting. Always was looking for something like this. Havenāt gotten around to playing with it, but will do so in the weekends.
Version 0.8.6 has been released.
Bug fixes
I found an issue with the callsite of certain constructors and Matthias solved it immediately by letting the instrumentation code emit an exception. Matthias is looking into a permanent solution, but for now itās good to have the instrumentator notify you of the edge case where it cannot produce valid continuationsā¦ yet. More info on this later, until then, download the latest version and pay attention to any warnings printed on the console.
Features
@@ final VirtualExchanger<String> ex = new VirtualExchanger<>();
new VirtualThread(new VirtualRunnable() {
@Override
public void run() throws SuspendExecution {
@@ String got = ex.exchange("object1a");
System.out.println("thread1 got: " + got);
@@ got = ex.exchange("object1b");
System.out.println("thread1 got: " + got);
}
}).start();
new VirtualThread(new VirtualRunnable() {
@Override
public void run() throws SuspendExecution {
@@ String got = ex.exchange("object2a");
System.out.println("thread2 got: " + got);
@@ got = ex.exchange("object2b");
System.out.println("thread2 got: " + got);
}
}).start();
// exchange #1
thread2 got: object1a
thread1 got: object2a
// exchange #2
thread1 got: object2b
thread2 got: object1b
Download files
I am currently using the Matthias continuations library and have found that it has greatly simplified my AI and network code. Perhaps i am a bit slow, but what have you added from that original lib? Is it just a green threads implementation?
Canāt you already run many many native threads in linux for example anyway (aka the old thread per socket web server or a Selector).
You can run many threads on any OS; the problem is that you are then dealing with synchronization and non-deterministic behaviour. And on ARM you even have significant memory barrier overhead as the ARM architecture doesnāt enforce memory consistency between cores.
Cas
Itās ājustā that, yes. If you browse through the code youāll see that ājustā is relative
I wrote this highlevel library on top of the continuations library, so that the concepts (processor, thread, sleep, lock, etc) are familiar for anybody having minimal experience with threading. Writing a proper scheduler (the VirtualProcessor) is not quite trivial, and it took me a few iterations to get it to where it is now. I think itās good to share the code, so others donāt have to reinvent the wheel, lowering the bar for usage of Matthias Mannās ingenious library.
What Cas said, and your native threads need at least a 256K stack size to do anything non trivial. When youād run the AI of every unit ingame on a native thread youād quickly run out of memory.
I added another update. Besides fixing methods which return ālongā - this version adds support to call suspendable methods as arguments for constructors (constructors itself are not suspendable).
This now allows constructs like this:
System.out.println(new StringBuilder(someSuspendableMethodWhichReturnString()).append(" Bla").toString());
// Eclipse generates the above code for the following Java statement:
System.out.println(someSuspendableMethodWhichReturnString()+" Bla");
Version 0.8.7 has been released.
Bug fixes
Download files
Anyone tried making a Server Client model with green thread clients?
Where does it lie in scalability between old Client/Thread and nio channels?
I started a HTTP client back in 2008 when I first wrote the lib, it is basically working - but I didnāt do much testing on it.
Most scalable servers use a model that isnāt thread-per-client, but they tend to use nio, which is probably not what you meant. JRockit uses a hybrid green/native model, and that runs some pretty heavy duty servers.
Well for that matter Ericsson has been since the mid-80s. Highly reliable and heavy workload.