-
Notifications
You must be signed in to change notification settings - Fork 49
localize(id): add indonesian translation #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yumanuralfath
wants to merge
10
commits into
zigcc:main
Choose a base branch
from
yumanuralfath:i18n/id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4c4eb6c
doc(section): update years footer
yumanuralfath 25bf27c
localize(id): add id support for zine config
yumanuralfath b21ffc8
localize(id): localize top section
yumanuralfath f3a952a
localize(id): localize main content to indonesian language
yumanuralfath 354ec8c
fix(space): fix excess space
yumanuralfath e6cbfc8
fix: fix sentence style
yumanuralfath ed25921
fix: typo word
yumanuralfath 77cc8a2
localize(id): add missing id localization
yumanuralfath 222f7e6
fix: fix style word follow KBBI
yumanuralfath a17bf76
fix: fix typo word
yumanuralfath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "site_title": "Zig Cookbook", | ||
| "introduction": "Pengenalan", | ||
| "contributing": "Kontribusi", | ||
| "license": "Lisensi", | ||
| "toggle_toc": "Alih daftar isi", | ||
| "prev": "Sebelumnya: ", | ||
| "next": "Selanjutnya: ", | ||
| "languages_menu": "Halaman ini tersedia dalam bahasa-bahasa berikut", | ||
| "footer_copyright": "Lisensi: text: CC BY-SA 4.0; code: MIT", | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| .title = "Pembacaan file baris per baris", | ||
| .date = "2026-04-29 10:58", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Terdapat tipe `Reader` di Zig, yang mana menyediakan berbagai metode untuk membaca file, seperti `readAll`, `readInt`. Di sini kita akan menggunakan `takeDelimiter` untuk pemisahan baris. | ||
|
|
||
| []($code.siteAsset('src/01-01.zig').language('zig')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| .title = "file Mmap", | ||
| .date = "2026-04-29 10:59", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Pembuatan memory map dari sebuah file dapat menggunakan [mmap](https://man7.org/linux/man-pages/man2/mmap.2.html) dan mensimulasikan beberapa pembacaan non-sekuensial dari file tersebut. Menggunakan memory map berarti kamu hanya perlu mengindeks ke dalam sebuah slice daripada harus berurusan dengan seek dalam menavigasi file. | ||
|
|
||
| []($code.siteAsset('src/01-02.zig').language('zig')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| .title = "Pencarian file-file yang telah diubah dalam 24 jam terakhir", | ||
| .date = "2026-04-29 11:06", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Dapatkan direktori kerja saat ini dengan memanggil `Io.Dir.cwd()`, kemudian lakukan iterasi file menggunakan `walk()`, yang akan secara rekursif mengulangi entri dalam direktori. | ||
|
|
||
| Untuk setiap entri, kita periksa apakah itu file, dan menggunakan `statFile()` untuk mengambil metadata file. | ||
|
|
||
| []($code.siteAsset('src/01-03.zig').language('zig')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| .title = "Cek keberadaan file", | ||
| .date = "2026-04-29 11:13", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Contoh ini menggunakan, `access` dalam memverifikasi keberadaan file; namun, agar dapat berfungsi dengan benar, seseorang harus secara khusus melakukan pemeriksaan tipe error `FileNotFound`. | ||
|
|
||
| []($code.siteAsset('src/01-04.zig').language('zig')) | ||
|
|
||
| Namun, ada jebakan yang dijelaskan dalam [dokumentasinya](https://github.com/ziglang/zig/blob/0.13.0/lib/std/fs/Dir.zig#L2390-L2396): | ||
|
|
||
| > Berhati-hatilah terhadap race condition [Time-Of-Check-Time-Of-Use](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use) saat menggunakan fungsi ini. | ||
| > Misalnya, alih-alih memeriksa apakah sebuah file ada lalu membukanya, cukup buka saja dan tangani error file not found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| .title = "Iterasi direktori", | ||
| .date = "2026-04-29 11:20", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
| Iterasi direktori | ||
|
|
||
| Tersedia metode `walk` yang praktis untuk tujuan ini, yang akan menelusuri direktori secara iteratif. | ||
|
|
||
| []($code.siteAsset('src/01-05.zig').language('zig')) | ||
|
|
||
| Urutan entri sistem file yang dikembalikan tidak ditentukan. Jika ada persyaratan untuk urutan pengembalian entri, seperti abjad atau kronologis waktu, maka urutkan sesuai kebutuhan. Jika tidak, biarkan dalam urutan aslinya yang tidak diurutkan. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| .title = "Menghitung digest SHA-256 dari sebuah file", | ||
| .date = "2026-04-29 11:23", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
| Menghitung digest SHA-256 dari sebuah file | ||
|
|
||
| Terdapat banyak implementasi algoritma kriptografi di std, `sha256`, `md5` didukung secara langsung. | ||
|
|
||
| []($code.siteAsset('src/02-01.zig').language('zig')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| .title = "Salt dan hash sebuah password menggunakan PBKDF2", | ||
| .date = "2026-04-29 11:25", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
| Salt dan hash sebuah password menggunakan PBKDF2 | ||
|
|
||
| Gunakan [`std.crypto.pwhash.pbkdf2`] untuk melakukan hashing pada password yang diberi salt menggunakan HMAC-SHA256. Ketika sudah produksi, salt harus dihasilkan secara acak menggunakan [`std.Io.randomSecure`]. | ||
|
|
||
| []($code.siteAsset('src/02-02.zig').language('zig')) | ||
|
|
||
| [`std.crypto.pwhash.pbkdf2`]: https://ziglang.org/documentation/0.16.0/std/#std.crypto.pwhash.pbkdf2 | ||
| [`std.Io.randomSecure`]: https://ziglang.org/documentation/0.16.0/std/#std.Io.randomSecure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| .title = "Salt dan hash sebuah password dengan Argon2", | ||
| .date = "2026-04-29 11:29", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
| Salt dan hash sebuh password dengan Argon2 | ||
|
|
||
|
|
||
| Program Zig ini menghasilkan kunci kriptografi dari password dan salt menggunakan algoritma hashing kata sandi Argon2id. Program ini menggunakan [std.crypto.pwhash.argon2] untuk melakukan hashing pada password yang diberi salt, di mana salt dihasilkan menggunakan [`std.Io.randomSecure`]. | ||
|
|
||
| []($code.siteAsset('src/02-03.zig').language('zig')) | ||
|
|
||
| [`std.crypto.pwhash.argon2`]: https://ziglang.org/documentation/0.16.0/std/#std.crypto.pwhash.argon2 | ||
| [`std.Io.randomSecure`]: https://ziglang.org/documentation/0.16.0/std/#std.Io.randomSecure | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| .title = "Mengukur waktu yang berlalu antara dua bagian kode", | ||
| .date = "2026-04-29 11:30", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| [`Io.Clock`] menyediakan stempel waktu monoton melalui `Io.Clock.awake.now(io)`. Memanggil `durationTo` pada stempel waktu akan mengembalikan `Duration` yang telah berlalu dalam nanodetik. | ||
|
|
||
| Untuk tidur, gunakan [`Io.sleep`] dengan nilai `Duration`. | ||
|
|
||
| []($code.siteAsset('src/03-01.zig').language('zig')) | ||
|
|
||
| [`Io.Clock`]: https://ziglang.org/documentation/0.16.0/std/#std.Io.Clock | ||
| [`Io.sleep`]: https://ziglang.org/documentation/0.16.0/std/#std.Io.sleep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| .title = "Listen ke port TCP/IP yang tidak digunakan", | ||
| .date = "2026-04-29 11:31", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Dalam contoh ini, port ditampilkan di konsol, dan program akan | ||
| mendengarkan hingga ada permintaan. Menggunakan `IpAddress` dengan `.loopback(0)` akan menetapkan | ||
| port acak. | ||
|
|
||
| []($code.siteAsset('src/04-01.zig').language('zig')) | ||
|
|
||
| Saat program dimulai, coba uji seperti ini: | ||
|
|
||
| ```bash | ||
| echo "hello zig" | nc localhost <port> | ||
| ``` | ||
|
|
||
| Secara default, program mendengarkan dengan IPv4. Jika Anda menginginkan IPv6, gunakan | ||
| `net.IpAddress{ .ip6 = .loopback(0) }` sebagai gantinya. | ||
|
|
||
| (Dan hubungkan ke sesuatu seperti `ip6-localhost`, tergantung pada cara | ||
| mesin Anda diatur.) | ||
|
|
||
| Bagian selanjutnya akan menunjukkan cara terhubung ke server ini menggunakan kode Zig. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| .title = "TCP Client", | ||
| .date = "2026-04-29 11:38", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Dalam contoh ini, kami mendemonstrasikan pembuatan klien TCP untuk terhubung ke server dari bagian sebelumnya. | ||
|
|
||
| Anda dapat menjalankannya menggunakan `zig build run-04-02 -- <port>`. | ||
|
|
||
| []($code.siteAsset('src/04-02.zig').language('zig')) | ||
|
|
||
| Secara default, program terhubung dengan IPv4. Jika Anda menginginkan IPv6, gunakan | ||
| `::1` sebagai pengganti `127.0.0.1`, ganti `net.IpAddress.parseIp4` dengan | ||
| `net.IpAddress.parseIp6`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| .title = "UDP Echo", | ||
| .date = "2026-04-29 11:40", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Mirip dengan contoh server TCP, program ini akan mendengarkan pada alamat IP dan port yang ditentukan, tetapi kali ini untuk datagram UDP. Jika data diterima, | ||
| data tersebut akan dikembalikan ke alamat pengirim. | ||
|
|
||
| Meskipun `std.Io.net` sebagian besar berfokus pada abstraksi untuk TCP (sejauh ini), kita masih dapat | ||
| menggunakan pemrograman soket untuk berkomunikasi melalui UDP. | ||
|
|
||
| []($code.siteAsset('src/04-03.zig').language('zig')) | ||
|
|
||
| Setelah menjalankan program, uji sebagai berikut dengan `nc`, menggunakan flag `-u` untuk UDP: | ||
|
|
||
| ```bash | ||
| echo "hello zig" | nc -u localhost <port> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| .title = "GET", | ||
| .date = "2026-04-29 11:43", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Mengurai URL yang diberikan dan membuat permintaan HTTP GET sinkron | ||
| dengan [`request`]. Mencetak status dan header [`Response`] yang diperoleh. | ||
|
|
||
| > Catatan: Karena dukungan HTTP masih dalam tahap awal, disarankan untuk menggunakan [libcurl](https://curl.se/libcurl/c/) untuk tugas yang kompleks. | ||
| > Dan jika buffer tidak cukup, akan mengembalikan `error.HttpHeadersOverSize` | ||
|
|
||
| []($code.siteAsset('src/05-01.zig').language('zig')) | ||
|
|
||
| [`request`]: https://ziglang.org/documentation/0.16.0/std/src/std/http/Client.zig.html#L992 | ||
| [`Response`]: https://ziglang.org/documentation/0.16.0/std/src/std/http/Client.zig.html#L322 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| .title = "POST", | ||
| .date = "2026-04-29 11:45", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Mengurai URL yang diberikan dan membuat permintaan HTTP POST sinkron | ||
| dengan [`request`]. Mencetak status [`Response`] yang diperoleh, dan data yang diterima dari server. | ||
|
|
||
| > Catatan: Karena dukungan HTTP masih dalam tahap awal, disarankan untuk menggunakan [libcurl](https://curl.se/libcurl/c/) untuk tugas yang kompleks. | ||
|
|
||
| []($code.siteAsset('src/05-02.zig').language('zig')) | ||
|
|
||
| [`request`]: https://ziglang.org/documentation/0.16.0/std/src/std/http/Client.zig.html#L992 | ||
| [`Response`]: https://ziglang.org/documentation/0.16.0/std/src/std/http/Client.zig.html#L322 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --- | ||
| .title = "http.Server - std", | ||
| .date = "2026-04-29 11:46", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Implementasi dasar `http.Server` telah diperkenalkan sejak Zig 0.12.0. | ||
|
|
||
| Untuk setiap koneksi, kami membuat thread baru untuk menanganinya, di `accept` thread tersebut akan: | ||
| 1. Pertama, ia menggunakan `defer` untuk memastikan koneksi ditutup saat dikembalikan. | ||
|
|
||
| 2. Kemudian menginisialisasi server HTTP untuk mulai mengurai permintaan. | ||
| 3. Untuk setiap permintaan, pertama-tama kami memeriksa apakah permintaan tersebut dapat ditingkatkan ke WebSocket. | ||
|
|
||
| - Jika berhasil, panggil `serveWebSocket`, jika tidak, panggil `serverHTTP` | ||
|
yumanuralfath marked this conversation as resolved.
|
||
|
|
||
| []($code.siteAsset('src/05-03.zig').language('zig')) | ||
|
|
||
| ## Tes | ||
|
|
||
| Untuk HTTP, kita bisa menggunakan `curl`: | ||
| ```bash | ||
| curl -v localhost:8080 | ||
| ``` | ||
| Hasilnya akan seperti ini: | ||
| ```bash | ||
| < HTTP/1.1 200 OK | ||
| < content-length: 32 | ||
| < custom header: custom value | ||
| < | ||
| Hello World from Zig HTTP server | ||
| ``` | ||
|
|
||
| Untuk WebSocket, kita bisa menggunakan konsol di `Developer Tools` browser Anda: | ||
|
|
||
| ```js | ||
| var webSocket = new WebSocket('ws://localhost:8080'); | ||
| webSocket.onmessage = function(data) { console.log(data); } | ||
| ``` | ||
| Kemudian kita bisa mengirim pesan seperti ini: | ||
| ```js | ||
| webSocket.send('abc') | ||
| ``` | ||
|
|
||
| [websocket-client]($image.siteAsset('images/websocket-client.webp')) | ||
|
|
||
| Lihat [Menulis aplikasi klien WebSocket - Web API | MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications) untuk detailnya. | ||
|
|
||
| ## Catatan | ||
| Implementasi standar menunjukkan kinerja yang sangat buruk. Jika Anda berencana melampaui eksperimen dasar, pertimbangkan untuk menggunakan pustaka alternatif seperti: | ||
| - <https://github.com/karlseguin/http.zig> | ||
| - <https://github.com/zigzap/zap> | ||
| - <https://github.com/mookums/zzz> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| .title = "Penghasil nilai acak", | ||
| .date = "2026-04-29 11:49", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Menghasilkan angka acak menggunakan [`std.Random.IoSource`], yang menyediakan generator angka acak yang aman secara kriptografis yang didukung oleh antarmuka I/O sistem. | ||
|
|
||
| []($code.siteAsset('src/06-01.zig').language('zig')) | ||
|
|
||
| [`std.Random.IoSource`]: https://ziglang.org/documentation/0.16.0/std/#std.Random.IoSource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| .title = "Membuat thread sementara", | ||
| .date = "2026-04-29 11:51", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Contoh ini menggunakan [`std.Thread`] untuk pemrograman konkuren dan paralel. | ||
| [`std.Thread.spawn`] membuat thread baru untuk menghitung hasilnya. | ||
|
|
||
| Contoh ini membagi array menjadi dua bagian dan melakukan pekerjaan di thread yang terpisah. | ||
|
|
||
| > Catatan: Untuk memastikan thread `t1` telah selesai ketika pembuatan `t2` gagal, kita menggunakan `defer t1.join()` segera setelah membuat `t1`. | ||
|
|
||
| []($code.siteAsset('src/07-01.zig').language('zig')) | ||
|
|
||
| [`std.Thread`]: https://ziglang.org/documentation/0.16.0/std/#std.Thread | ||
| [`std.Thread.spawn`]: https://ziglang.org/documentation/0.16.0/std/#std.Thread.spawn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| .title = "Berbagi data antara dua thread", | ||
| .date = "2026-04-29 11:52", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Ketika kita ingin mengubah data yang dibagi antar thread, [`Mutex`] (**Mut**ually **ex**clusive flag) harus digunakan untuk menyinkronkan thread, karena jika tidak, hasilnya bisa tidak terduga. | ||
|
|
||
| []($code.siteAsset('src/07-02.zig').language('zig')) | ||
| Jika kita menghapus perlindungan Mutex, hasilnya kemungkinan besar akan kurang dari 30.000. | ||
|
|
||
| [`Mutex`]: https://ziglang.org/documentation/0.16.0/std/#std.Io.Mutex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| .title = "Thread pool", | ||
| .date = "2026-04-29 11:56", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Thread pool menyelesaikan dua masalah berbeda: | ||
| 1. Biasanya memberikan peningkatan performa saat menjalankan tugas asinkron dalam jumlah besar, karena berkurangnya overhead pemanggilan per tugas, dan | ||
| 2. Menyediakan cara untuk membatasi dan mengelola sumber daya, termasuk thread, yang digunakan saat menjalankan sekumpulan tugas. | ||
|
|
||
|
|
||
| Dalam contoh ini, kita membuat 10 tugas menggunakan `Io.Group`, dan memanggil `await` untuk menunggu semuanya selesai. | ||
|
|
||
| []($code.siteAsset('src/07-03.zig').language('zig')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| .title = "Run Once", | ||
| .date = "2026-04-29 11:57", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
|
|
||
| `std.once` telah dihapus di Zig 0.16. Di sini kita mengimplementasikan semantik "jalankan tepat sekali" secara manual menggunakan protokol atomik tiga-status: | ||
|
|
||
| - **0 (idle)** – belum ada thread yang memulai pekerjaan. | ||
| - **1 (running)** – satu thread berhasil merebut kesempatan dan sedang menjalankan tugasnya. | ||
| - **2 (done)** – tugas telah selesai; semua thread dapat langsung kembali. | ||
|
|
||
| Ini memastikan suatu fungsi hanya dijalankan tepat satu kali, terlepas dari berapa banyak thread yang mencoba memanggilnya. Berguna untuk pola singleton dan operasi inisialisasi sekali pakai. | ||
|
|
||
| []($code.siteAsset('src/07-04.zig').language('zig')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| .title = "Memeriksa jumlah core CPU logis", | ||
| .date = "2026-04-29 11:58", | ||
| .author = "ZigCC", | ||
| .layout = "section.shtml", | ||
| --- | ||
|
|
||
| Menampilkan jumlah core CPU logis pada mesin yang sedang berjalan menggunakan [`std.Thread.getCpuCount`]. | ||
|
|
||
| []($code.siteAsset('src/08-01.zig').language('zig')) | ||
|
|
||
| [`std.Thread.getCpuCount`]: https://ziglang.org/documentation/0.16.0/std/#std.Thread.getCpuCount |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.