ThreadFuck
Brainfuck with threads. Every line is a subprogram, and any thread can start another one on any line.
None1, 2024 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
None1 made ThreadFuck in 2024, after brainfuck and Bukkake. Each line of a program is a subprogram. The main thread runs the first line, and ! starts a new thread on the line its selector points at. Every thread has its own tape and pointer, and all threads share one public tape with one public pointer. ~ switches a thread between the two.
Read the story
The specification shows how easily that goes wrong. Two threads that print at once mix their letters, two threads on the public pointer trample each other's cells, and two threads that wait for each other wait forever.
The machine
| Command | Does |
|---|---|
+ - < > . , [ ] | As in brainfuck, on the active pointer |
~ | Switch between the private and the public pointer |
! | Start a thread on the selected line |
v ^ | Select the line below or above, wrapping round |
* | Wait until every other thread has ended |
A thread ends at the end of its line, and the program ends when no thread is left. In this implementation threads take turns, one command each per round, in the order they were made. Cells are bytes that wrap.
Example
The Lock program.
The Lock program. The main thread selects line 2, starts a thread there and waits for it with *. Then it prints the same greeting itself.
The first undefined output starts two threads on line 2 and waits for neither, so they print at the same time. The specification calls the output undefined; with turns of one command each, every letter comes out twice.
The Lock 2 program passes a lock back and forth on the public tape and is said to always print DEFABC over and over. In this implementation it prints ABCDEF over and over. The second thread moves the shared pointer one cell right to test its own lock, and the first thread, waiting on the same pointer, sees the 0 there and goes first.
Patterns it teaches
- Turing tarpit: brainfuck's eight commands with five more for threads.
- Nondeterminism: the output depends on how the threads take turns.
Further
See also
ThreadFuck builds on Brainfuck.
Concurrent programming
Brainfuck derivatives
Write your own in Run Convert a program from ThreadFuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: threadfuck.
Command line
shib run threadfuck -e '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'shib manual threadfuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/threadfuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org