September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,7 +1,6 @@
|
|||
let words = ["Enjoy", "Rosetta", "Code"]
|
||||
|
||||
for word in words:
|
||||
async (w) => (
|
||||
(word) |> async (w) =>
|
||||
sleep(random())
|
||||
print(w)
|
||||
)(word)
|
||||
|
|
|
|||
34
Task/Concurrent-computing/Neko/concurrent-computing.neko
Normal file
34
Task/Concurrent-computing/Neko/concurrent-computing.neko
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
Concurrent computing, in Neko
|
||||
*/
|
||||
|
||||
var thread_create = $loader.loadprim("std@thread_create", 2);
|
||||
|
||||
var subtask = function(message) {
|
||||
$print(message, "\n");
|
||||
}
|
||||
|
||||
/* The thread functions happen so fast as to look sequential */
|
||||
thread_create(subtask, "Enjoy");
|
||||
thread_create(subtask, "Rosetta");
|
||||
thread_create(subtask, "Code");
|
||||
|
||||
/* slow things down */
|
||||
var sys_sleep = $loader.loadprim("std@sys_sleep", 1);
|
||||
var random_new = $loader.loadprim("std@random_new", 0);
|
||||
var random_int = $loader.loadprim("std@random_int", 2);
|
||||
|
||||
var randomsleep = function(message) {
|
||||
var r = random_new();
|
||||
var sleep = random_int(r, 3);
|
||||
sys_sleep(sleep);
|
||||
$print(message, "\n");
|
||||
}
|
||||
|
||||
$print("\nWith random delays\n");
|
||||
thread_create(randomsleep, "Enjoy");
|
||||
thread_create(randomsleep, "Rosetta");
|
||||
thread_create(randomsleep, "Code");
|
||||
|
||||
/* Let the threads complete */
|
||||
sys_sleep(4);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
my @words = <Enjoy Rosetta Code>;
|
||||
@words.race(:batch(1)).map: { sleep rand; say $_ };
|
||||
|
|
@ -1,10 +1,15 @@
|
|||
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win 32
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> from concurrent import futures
|
||||
>>> with futures.ProcessPoolExecutor() as executor:
|
||||
... _ = list(executor.map(print, 'Enjoy Rosetta Code'.split()))
|
||||
...
|
||||
Enjoy
|
||||
Rosetta
|
||||
Code
|
||||
>>>
|
||||
import asyncio
|
||||
|
||||
|
||||
async def print_(string: str) -> None:
|
||||
print(string)
|
||||
|
||||
|
||||
async def main():
|
||||
strings = ['Enjoy', 'Rosetta', 'Code']
|
||||
coroutines = map(print_, strings)
|
||||
await asyncio.gather(*coroutines)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import threading
|
||||
import random
|
||||
|
||||
def echo(text):
|
||||
print(text)
|
||||
|
||||
threading.Timer(random.random(), echo, ("Enjoy",)).start()
|
||||
threading.Timer(random.random(), echo, ("Rosetta",)).start()
|
||||
threading.Timer(random.random(), echo, ("Code",)).start()
|
||||
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win 32
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> from concurrent import futures
|
||||
>>> with futures.ProcessPoolExecutor() as executor:
|
||||
... _ = list(executor.map(print, 'Enjoy Rosetta Code'.split()))
|
||||
...
|
||||
Enjoy
|
||||
Rosetta
|
||||
Code
|
||||
>>>
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@ import random
|
|||
def echo(text):
|
||||
print(text)
|
||||
|
||||
for text in ["Enjoy", "Rosetta", "Code"]:
|
||||
threading.Timer(random.random(), echo, (text,)).start()
|
||||
threading.Timer(random.random(), echo, ("Enjoy",)).start()
|
||||
threading.Timer(random.random(), echo, ("Rosetta",)).start()
|
||||
threading.Timer(random.random(), echo, ("Code",)).start()
|
||||
|
|
|
|||
|
|
@ -1,14 +1,8 @@
|
|||
import random, sys, time
|
||||
import threading
|
||||
import random
|
||||
|
||||
lock = threading.Lock()
|
||||
def echo(text):
|
||||
print(text)
|
||||
|
||||
def echo(s):
|
||||
time.sleep(1e-2*random.random())
|
||||
# use `.write()` with lock due to `print` prints empty lines occasionally
|
||||
with lock:
|
||||
sys.stdout.write(s)
|
||||
sys.stdout.write('\n')
|
||||
|
||||
for line in 'Enjoy Rosetta Code'.split():
|
||||
threading.Thread(target=echo, args=(line,)).start()
|
||||
for text in ["Enjoy", "Rosetta", "Code"]:
|
||||
threading.Timer(random.random(), echo, (text,)).start()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
from __future__ import print_function
|
||||
from multiprocessing import Pool
|
||||
import random, sys, time
|
||||
import threading
|
||||
|
||||
def main():
|
||||
p = Pool()
|
||||
p.map(print, 'Enjoy Rosetta Code'.split())
|
||||
lock = threading.Lock()
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
def echo(s):
|
||||
time.sleep(1e-2*random.random())
|
||||
# use `.write()` with lock due to `print` prints empty lines occasionally
|
||||
with lock:
|
||||
sys.stdout.write(s)
|
||||
sys.stdout.write('\n')
|
||||
|
||||
for line in 'Enjoy Rosetta Code'.split():
|
||||
threading.Thread(target=echo, args=(line,)).start()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import random
|
||||
from twisted.internet import reactor, task, defer
|
||||
from twisted.python.util import println
|
||||
from __future__ import print_function
|
||||
from multiprocessing import Pool
|
||||
|
||||
delay = lambda: 1e-4*random.random()
|
||||
d = defer.DeferredList([task.deferLater(reactor, delay(), println, line)
|
||||
for line in 'Enjoy Rosetta Code'.split()])
|
||||
d.addBoth(lambda _: reactor.stop())
|
||||
reactor.run()
|
||||
def main():
|
||||
p = Pool()
|
||||
p.map(print, 'Enjoy Rosetta Code'.split())
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
from __future__ import print_function
|
||||
import random
|
||||
import gevent
|
||||
from twisted.internet import reactor, task, defer
|
||||
from twisted.python.util import println
|
||||
|
||||
delay = lambda: 1e-4*random.random()
|
||||
gevent.joinall([gevent.spawn_later(delay(), print, line)
|
||||
for line in 'Enjoy Rosetta Code'.split()])
|
||||
d = defer.DeferredList([task.deferLater(reactor, delay(), println, line)
|
||||
for line in 'Enjoy Rosetta Code'.split()])
|
||||
d.addBoth(lambda _: reactor.stop())
|
||||
reactor.run()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
from __future__ import print_function
|
||||
import random
|
||||
import gevent
|
||||
|
||||
delay = lambda: 1e-4*random.random()
|
||||
gevent.joinall([gevent.spawn_later(delay(), print, line)
|
||||
for line in 'Enjoy Rosetta Code'.split()])
|
||||
15
Task/Concurrent-computing/VBA/concurrent-computing.vba
Normal file
15
Task/Concurrent-computing/VBA/concurrent-computing.vba
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Private Sub Enjoy()
|
||||
Debug.Print "Enjoy"
|
||||
End Sub
|
||||
Private Sub Rosetta()
|
||||
Debug.Print "Rosetta"
|
||||
End Sub
|
||||
Private Sub Code()
|
||||
Debug.Print "Code"
|
||||
End Sub
|
||||
Public Sub concurrent()
|
||||
when = Now + TimeValue("00:00:01")
|
||||
Application.OnTime when, "Enjoy"
|
||||
Application.OnTime when, "Rosetta"
|
||||
Application.OnTime when, "Code"
|
||||
End Sub
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Imports System.Threading
|
||||
Module Module1
|
||||
Dim rnd As New Random()
|
||||
Sub Main()
|
||||
Parallel.ForEach("Enjoy Rosetta Code".Split(" "), Sub(s)
|
||||
Thread.Sleep(rnd.Next(25)) : Console.WriteLine(s)
|
||||
End Sub)
|
||||
End Sub
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue