Skip to content

Commit 6ae548e

Browse files
committed
Starting the article
1 parent 173a19a commit 6ae548e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

20th/articles/rfc1.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# RFC 1, by Bryan C. Warnock: Threads
2+
3+
It might ot might not be the case that the need for a real multithreaded architecture in Perl was the real motive behind the creation of what was initially called simply Perl, then Perl 6, and eventually [Raku](https://raku.org).
4+
5+
It was probably late 90s or early 10s, when we had a contract with a big company that needed to download stuff from the web really fast. We needed those threads, and they finally arrived in Perl 5.10. However, our threads were very basic, didn't need any kind of communication, just the bare parallel thing, and underneath them, operating system processes were used; there were no real *threads* at the Perl VM level. And they were sorely needed. Which is why [RFC1](https://raku.org/archive/rfc/1.html) read:
6+
7+
> Implementation of Threads in Perl
8+
9+
It was originally proposed in August 1th (hence the 20th aniversary thing), and finally *frozen* a couple of month later, by September 28th.
10+
11+
It basically proposes a way to implement low-level threads, including new namespaces (`global`, for sharing variables among threads) as well as the `Threads` class, with this example:
12+
13+
```
14+
use Threads;
15+
# the main thread has all four above in its arena
16+
17+
my $thread2 = Threads->new(\&start_thread2);
18+
#...
19+
20+
sub start_thread2 { ... }
21+
```
22+
23+
The main thread is implicit, and gets all other modules into its namespace, the second one inherits from the main thread. It makes sense, in general, except it's a very low level mechanism to use threads, and in fact it looks more like a way to handle processes than what we call nowadays threads. There's another RFC for those, which are called ["lightweight threads"](https://raku.org/archive/rfc/178.html), which was started a few week later and frozen pretty much at the same time. It contains the graphic simile:
24+
25+
26+
> Perl → Swiss-army chain saw; Perl with threads → juggling chain saws
27+
28+
It's difficult to see what's the difference between them, except for the explicit sharing of variables and the fact that it uses `Thread` instead of `Threads` as the main class.
29+
30+
Eventually, that was the keyword chosen for threads in Raku: [`Thread`](https://docs.raku.org/type/Thread.html). This uses `new` to create a thread, but you have then to issue a `.run` to actually run it. Alternatively, you can simply use `.start` to create *and* run a thread inmediately.
31+

0 commit comments

Comments
 (0)