Skip to content

Commit 5b114c4

Browse files
committed
docs(posts): Update shared objects posts and translation script
1 parent abf3db4 commit 5b114c4

File tree

5 files changed

+51
-318
lines changed

5 files changed

+51
-318
lines changed

_posts/ar/2025-01-28-shared-objects-ar.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
---
22
audio: true
3-
lang: en
3+
lang: ar
44
layout: post
5-
title: Shared Objects in Multiple Threads
5+
title: الكائنات المشتركة بين عدة خيوط
6+
translated: true
67
---
78

8-
## Lesson
9+
## الدرس
910

10-
The code demonstrates a peculiar bug that appears inconsistently. Sometimes the bug occurs, and sometimes it does not, making it difficult to reproduce and debug.
11+
يوضح الكود خطأ غريبًا يظهر بشكل غير متسق. في بعض الأحيان يحدث الخطأ، وفي أحيان أخرى لا يحدث، مما يجعل من الصعب إعادة إنتاجه وتصحيحه.
1112

12-
This intermittent behavior stems from the way the `translate_markdown_file` function, particularly the `translate_front_matter` function, handles shared data. These functions might be accessing and modifying shared data structures, such as dictionaries or lists, without proper synchronization.
13+
هذا السلوك المتقطع ناتج عن الطريقة التي تتعامل بها وظيفة `translate_markdown_file`، وخاصة وظيفة `translate_front_matter`، مع البيانات المشتركة. قد تكون هذه الوظائف تصل وتعدل هياكل البيانات المشتركة، مثل القواميس أو القوائم، دون تزامن مناسب.
1314

14-
When multiple threads access and modify the same data concurrently, it can lead to race conditions. Race conditions occur when the final state of the data depends on the unpredictable order in which threads execute. This can result in data corruption, unexpected program behavior, and the intermittent bugs you are observing.
15+
عندما تصل عدة خيوط (threads) إلى نفس البيانات وتعدلها بشكل متزامن، يمكن أن يؤدي ذلك إلى حالات سباق (race conditions). تحدث حالات السباق عندما تعتمد الحالة النهائية للبيانات على الترتيب غير المتوقع الذي تنفذ به الخيوط. يمكن أن يؤدي ذلك إلى تلف البيانات، وسلوك غير متوقع للبرنامج، والأخطاء المتقطعة التي تلاحظها.
1516

16-
To fix this, you should either avoid sharing mutable data between threads or use proper synchronization mechanisms, such as locks, to protect shared data. In this case, the `front_matter_dict` is being modified in place, which is not thread-safe. The fix is to create a copy of the dictionary before modifying it. This is already done in the code, but it's important to understand why it's necessary.
17+
لإصلاح هذا، يجب عليك إما تجنب مشاركة البيانات القابلة للتغيير بين الخيوط أو استخدام آليات التزامن المناسبة، مثل الأقفال (locks)، لحماية البيانات المشتركة. في هذه الحالة، يتم تعديل `front_matter_dict` مباشرة، وهو أمر غير آمن للخيوط. الإصلاح هو إنشاء نسخة من القاموس قبل تعديله. هذا يتم بالفعل في الكود، ولكن من المهم فهم سبب ضرورة ذلك.
1718

18-
## Context
19+
## السياق
1920

2021
```python
2122
with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_THREADS) as executor:
@@ -36,7 +37,7 @@ To fix this, you should either avoid sharing mutable data between threads or use
3637
print(f"A thread failed: {e}")
3738
```
3839

39-
## Before
40+
## قبل
4041

4142
```python
4243
def translate_front_matter(front_matter, target_language, input_file):
@@ -90,7 +91,7 @@ def translate_front_matter(front_matter, target_language, input_file):
9091
return front_matter
9192
```
9293

93-
## After
94+
## بعد
9495

9596
```python
9697
def translate_front_matter(front_matter, target_language, input_file):
@@ -134,4 +135,4 @@ def translate_front_matter(front_matter, target_language, input_file):
134135
except yaml.YAMLError as e:
135136
print(f" Error parsing front matter: {e}")
136137
return front_matter
137-
```
138+
```

_posts/ar/2025-01-28-shared-objects-en-ar.md

Lines changed: 0 additions & 138 deletions
This file was deleted.

_posts/fr/2025-01-28-shared-objects-en-fr.md

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)