added translated slot for posts

This commit is contained in:
ClovertaTheTrilobita 2026-03-29 22:23:23 +03:00
parent 754717c280
commit f1dd997c9a
11 changed files with 140 additions and 14 deletions

61
src/blog/en/post-3.md Normal file
View file

@ -0,0 +1,61 @@
---
title: "[Study Notes] A Step-by-Step Analysis of Why Peterson's Algorithm Does Not Deadlock"
pubDate: 2025-06-10
description: "Study notes on Peterson's Algorithm"
author: "Cloverta"
image:
url: "https://files.seeusercontent.com/2026/03/25/sTq9/pasted-image-1774456630694.webp"
alt: "zako2"
tags: ["Peterson's algorithm", "Operating System"]
---
In my OS course, I came across an interesting algorithm — Peterson's Algorithm. So why does Peterson's Algorithm satisfy the three conditions: "mutual exclusion", "progress", and "bounded waiting"?
First, here is the pseudocode:
```cpp
bool flag[2]; // Array indicating intention to enter critical section, initially false
int turn = 0; // turn indicates which process is given priority to enter the critical section
// Process P0
flag[0] = true; // First set its own flag to true, declaring it needs the critical section
turn = 1; // Let P1 execute first if P1 needs the critical section
while (flag[1] && turn == 1); // Check if P1 needs the critical section
CRITICAL_SECTION;
flag[0] = false;
REMAINDER_SECTION;
// Process P1
flag[1] = true;
turn = 0;
while (flag[0] && turn == 0);
CRITICAL_SECTION;
flag[1] = false;
REMAINDER_SECTION;
```
Let's analyze it case by case.
Assume that P0 and P1 are executing concurrently, and coincidentally they both complete the first step together — both of their flags are false.
At this point:
> **[Case 1]**
> If P0 gets on the CPU first, it sets turn = 1;
> P1 gets on the CPU, sets turn = 0;
> P0 gets on the CPU, checks flag and turn — finds turn has been changed to 0, the waiting condition is not met, so P0 enters the critical section;
> P1 gets on the CPU, checks flag and turn — finds flag[0] is true and turn is unchanged, so P1 waits.
> P0 gets on the CPU and finishes using the critical section, sets flag[1] = false;
> P1 gets on the CPU, finds flag[0] is false, stops waiting and enters the critical section;
>
> **[Case 2]**
> If P0 gets on the CPU first, sets turn = 1;
> P0 continues using the CPU, finds flag[0] is true and turn is still 1, the waiting condition is met, so P0 waits;
> P1 gets on the CPU, sets turn = 0;
> P1 continues using the CPU, finds flag[1] is true and turn is still 0, the waiting condition is met, so P1 waits;
> P0 gets on the CPU, finds turn has become 0, the waiting condition is not met, so P0 exits the wait and enters the critical section;
> P1 gets on the CPU, finds the waiting condition still holds, so P1 continues waiting;
> P0 gets on the CPU and finishes using the CPU, sets flag[0] = false;
> P1 gets on the CPU, finds flag[0] == false, the waiting condition is not met, stops waiting and enters the critical section;
_YES, IT WORKS ON MY MACHINE._

24
src/blog/zh/post-1.md Normal file
View file

@ -0,0 +1,24 @@
---
title: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试'
pubDate: 2022-07-01
description: 'This is the first post of my new Astro blog.'
author: 'Astro Learner'
image:
url: 'https://s2.loli.net/2022/05/01/UNzy8c6pTHBSuMO.jpg'
alt: 'The Astro logo on a dark background with a pink glow.'
tags: ["astro", "blogging", "learning in public", "Hello"]
---
Welcome to my _new blog_ about learning Astro! Here, I will share my learning journey as I build a new website.
## What I've accomplished
1. **Installing Astro**: First, I created a new Astro project and set up my online accounts.
2. **Making Pages**: I then learned how to make pages by creating new `.astro` files and placing them in the `src/pages/` folder.
3. **Making Blog Posts**: This is my first blog post! I now have Astro pages and Markdown posts!
## What's next
I will finish the Astro tutorial, and then keep adding more posts. Watch this space for more to come.

24
src/blog/zh/post-2.md Normal file
View file

@ -0,0 +1,24 @@
---
title: 'My Second Blog Post'
pubDate: 2022-07-01
description: 'This is the first post of my new Astro blog.'
author: 'Astro Learner'
image:
url: 'https://files.seeusercontent.com/2026/03/25/0rSi/rikka-manga.jpeg'
alt: 'The Astro logo on a dark background with a pink glow.'
tags: ["astro", "blogging", "learning in public"]
---
Welcome to my _new blog_ about learning Astro! Here, I will share my learning journey as I build a new website.
## What I've accomplished
1. **Installing Astro**: First, I created a new Astro project and set up my online accounts.
2. **Making Pages**: I then learned how to make pages by creating new `.astro` files and placing them in the `src/pages/` folder.
3. **Making Blog Posts**: This is my first blog post! I now have Astro pages and Markdown posts!
## What's next
I will finish the Astro tutorial, and then keep adding more posts. Watch this space for more to come.

View file

@ -13,7 +13,7 @@ tags: ["peterson算法", "操作系统"]
先上伪代码:
```
```cpp
bool flag[2]; // 表示进入临界区意愿的数组初始值都为false
int turn = 0; // turn表示优先让哪个进程进入临界区

View file

@ -79,7 +79,12 @@ const sortedPosts = [...allPosts].sort(
new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime(),
);
const latestPosts = sortedPosts.slice(0, 5);
const filteredPosts = sortedPosts.filter((post: any) => {
const postLang = post.id.split("/")[0];
return postLang === lang;
});
const latestPosts = filteredPosts.slice(0, 5);
---
<ul>
@ -89,7 +94,10 @@ const latestPosts = sortedPosts.slice(0, 5);
.toISOString()
.split("T")[0];
const pathname = `/${post.id}/`;
const [postLang, ...slugParts] = post.id.split("/");
const slug = slugParts.join("/");
const pathname = `/${slug}/`;
const matchedDiscussion = discussions.find((d: DiscussionNode) => {
return normalizePath(d.title) === normalizePath(pathname);
@ -106,7 +114,7 @@ const latestPosts = sortedPosts.slice(0, 5);
return (
<PostItem
url={`/${lang}/posts/${post.id}/`}
url={`/${postLang}/posts/${slug}/`}
title={post.data.title}
description={post.data.description}
date={formattedDate}

View file

@ -11,7 +11,12 @@ const sortedPosts = [...allPosts].sort(
new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime(),
);
const groupedPosts = sortedPosts.reduce((acc: any[], post: any) => {
const filteredPosts = sortedPosts.filter((post: any) => {
const postLang = post.id.split("/")[0];
return postLang === lang;
});
const groupedPosts = filteredPosts.reduce((acc: any[], post: any) => {
const month = new Date(post.data.pubDate).toISOString().slice(0, 7);
const lastGroup = acc[acc.length - 1];

View file

@ -16,7 +16,7 @@ const blog = defineCollection({
url: z.string(),
alt: z.string()
}),
tags: z.array(z.string())
tags: z.array(z.string()),
})
});

View file

@ -19,7 +19,7 @@ const pageTitle = t.home.title;
<h1 class="page-title">
<span>{pageTitle}</span>
<a
href={`${import.meta.env.SITE}/rss.xml`}
href={`/rss.xml`}
target="_blank"
rel="noopener noreferrer"
aria-label="RSS Feed"

View file

@ -4,26 +4,30 @@ import MarkdownPostLayout from "@/layouts/MarkdownPostLayout.astro";
export async function getStaticPaths() {
const posts = await getCollection("blog");
const langs = ["zh", "en"];
return langs.flatMap((lang) =>
posts.map((post) => ({
return posts.map((post) => {
const [lang, ...slugParts] = post.id.split("/");
return {
params: {
lang,
slug: post.id,
slug: slugParts.join("/"),
},
props: {
post,
lang,
},
})),
);
};
});
}
const { post, lang } = Astro.props;
const { Content } = await render(post);
const [postLang, ...slugParts] = post.id.split("/");
const slug = slugParts.join("/");
---
<MarkdownPostLayout frontmatter={post.data} lang={lang} postId={post.id}>
<MarkdownPostLayout frontmatter={post.data} lang={lang} postId={slug}>
<Content />
</MarkdownPostLayout>