Skip to content

Commit 4896e49

Browse files
committed
add mutex lock problem when using in while let
1 parent 8e6b5da commit 4896e49

13 files changed

+168
-55
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{c+c1}{// \PYGZhy{}\PYGZhy{}snip\PYGZhy{}\PYGZhy{}}
3+
4+
\PYG{k}{impl}\PYG{+w}{ }\PYG{n}{Worker}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
5+
\PYG{+w}{ }\PYG{k}{fn} \PYG{n+nf}{new}\PYG{p}{(}\PYG{n}{id}: \PYG{k+kt}{usize}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{receiver}: \PYG{n+nc}{Arc}\PYG{o}{\PYGZlt{}}\PYG{n}{Mutex}\PYG{o}{\PYGZlt{}}\PYG{n}{mpsc}::\PYG{n}{Receiver}\PYG{o}{\PYGZlt{}}\PYG{n}{Job}\PYG{o}{\PYGZgt{}\PYGZgt{}\PYGZgt{}}\PYG{p}{)}\PYG{+w}{ }\PYGZhy{}\PYGZgt{} \PYG{n+nc}{Worker}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
6+
\PYG{+w}{ }\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n}{thread}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{thread}::\PYG{n}{spawn}\PYG{p}{(}\PYG{k}{move}\PYG{+w}{ }\PYG{o}{||}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
7+
\PYG{+w}{ }\PYG{k}{while}\PYG{+w}{ }\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n+nb}{Ok}\PYG{p}{(}\PYG{n}{job}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{receiver}\PYG{p}{.}\PYG{n}{lock}\PYG{p}{().}\PYG{n}{unwrap}\PYG{p}{().}\PYG{n}{recv}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
8+
\PYG{+w}{ }\PYG{n+nf+fm}{println!}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Worker \PYGZob{}id\PYGZcb{} got a job; executing.\PYGZdq{}}\PYG{p}{);}
9+
10+
\PYG{+w}{ }\PYG{n}{job}\PYG{p}{();}
11+
\PYG{+w}{ }\PYG{p}{\PYGZcb{}}
12+
\PYG{+w}{ }\PYG{p}{\PYGZcb{});}
13+
14+
\PYG{+w}{ }\PYG{n}{Worker}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{n}{id}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{thread}\PYG{+w}{ }\PYG{p}{\PYGZcb{}}
15+
\PYG{+w}{ }\PYG{p}{\PYGZcb{}}
16+
\PYG{p}{\PYGZcb{}}
17+
\end{Verbatim}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{n}{MutexGuard}\PYG{o}{\PYGZlt{}}\PYG{n}{T}\PYG{o}{\PYGZgt{}}
3+
\end{Verbatim}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{n}{Mutex}
3+
\end{Verbatim}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{n}{LockResult}\PYG{o}{\PYGZlt{}}\PYG{n}{MutexGuard}\PYG{o}{\PYGZlt{}}\PYG{n}{T}\PYG{o}{\PYGZgt{}\PYGZgt{}}
3+
\end{Verbatim}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
2+
\PYG{k+kd}{let}\PYG{+w}{ }\PYG{n}{job}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{receiver}\PYG{p}{.}\PYG{n}{lock}\PYG{p}{().}\PYG{n}{unwrap}\PYG{p}{().}\PYG{n}{recv}\PYG{p}{().}\PYG{n}{unwrap}\PYG{p}{()}
3+
\end{Verbatim}

code/http13.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// --snip--
2+
3+
impl Worker {
4+
fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
5+
let thread = thread::spawn(move || {
6+
while let Ok(job) = receiver.lock().unwrap().recv() {
7+
println!("Worker {id} got a job; executing.");
8+
9+
job();
10+
}
11+
});
12+
13+
Worker { id, thread }
14+
}
15+
}

rust.aux

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -899,22 +899,26 @@
899899
\@writefile{nav}{\headcommand {\beamer@framepages {397}{397}}}
900900
\@writefile{nav}{\headcommand {\slideentry {19}{0}{24}{398/398}{}{0}}}
901901
\@writefile{nav}{\headcommand {\beamer@framepages {398}{398}}}
902-
\@writefile{toc}{\beamer@sectionintoc {20}{Tokio}{399}{0}{20}}
903-
\@writefile{nav}{\headcommand {\beamer@sectionpages {375}{398}}}
904-
\@writefile{nav}{\headcommand {\beamer@subsectionpages {375}{398}}}
905-
\@writefile{nav}{\headcommand {\sectionentry {20}{Tokio}{399}{Tokio}{0}}}
906-
\@writefile{nav}{\headcommand {\slideentry {20}{0}{1}{399/399}{}{0}}}
902+
\@writefile{nav}{\headcommand {\slideentry {19}{0}{25}{399/399}{}{0}}}
907903
\@writefile{nav}{\headcommand {\beamer@framepages {399}{399}}}
908-
\@writefile{nav}{\headcommand {\beamer@sectionpages {399}{399}}}
909-
\@writefile{nav}{\headcommand {\beamer@subsectionpages {399}{399}}}
910-
\@writefile{nav}{\headcommand {\sectionentry {21}{Acknowledgement}{400}{Acknowledgement}{0}}}
911-
\@writefile{nav}{\headcommand {\slideentry {21}{0}{1}{400/400}{}{0}}}
904+
\@writefile{nav}{\headcommand {\slideentry {19}{0}{26}{400/400}{}{0}}}
912905
\@writefile{nav}{\headcommand {\beamer@framepages {400}{400}}}
913-
\@writefile{nav}{\headcommand {\beamer@partpages {1}{400}}}
914-
\@writefile{nav}{\headcommand {\beamer@subsectionpages {400}{400}}}
915-
\@writefile{nav}{\headcommand {\beamer@sectionpages {400}{400}}}
916-
\@writefile{nav}{\headcommand {\beamer@documentpages {400}}}
917-
\@writefile{nav}{\headcommand {\gdef \inserttotalframenumber {400}}}
906+
\@writefile{toc}{\beamer@sectionintoc {20}{Tokio}{401}{0}{20}}
907+
\@writefile{nav}{\headcommand {\beamer@sectionpages {375}{400}}}
908+
\@writefile{nav}{\headcommand {\beamer@subsectionpages {375}{400}}}
909+
\@writefile{nav}{\headcommand {\sectionentry {20}{Tokio}{401}{Tokio}{0}}}
910+
\@writefile{nav}{\headcommand {\slideentry {20}{0}{1}{401/401}{}{0}}}
911+
\@writefile{nav}{\headcommand {\beamer@framepages {401}{401}}}
912+
\@writefile{nav}{\headcommand {\beamer@sectionpages {401}{401}}}
913+
\@writefile{nav}{\headcommand {\beamer@subsectionpages {401}{401}}}
914+
\@writefile{nav}{\headcommand {\sectionentry {21}{Acknowledgement}{402}{Acknowledgement}{0}}}
915+
\@writefile{nav}{\headcommand {\slideentry {21}{0}{1}{402/402}{}{0}}}
916+
\@writefile{nav}{\headcommand {\beamer@framepages {402}{402}}}
917+
\@writefile{nav}{\headcommand {\beamer@partpages {1}{402}}}
918+
\@writefile{nav}{\headcommand {\beamer@subsectionpages {402}{402}}}
919+
\@writefile{nav}{\headcommand {\beamer@sectionpages {402}{402}}}
920+
\@writefile{nav}{\headcommand {\beamer@documentpages {402}}}
921+
\@writefile{nav}{\headcommand {\gdef \inserttotalframenumber {402}}}
918922
\gdef\minted@oldcachelist{,
919923
solarized-light.pygstyle,
920924
19CF355A1FE33BFD89A18299A73F7F86BFBE258336EB5E56A554DD9A10B78B90.pygtex,
@@ -1533,6 +1537,13 @@
15331537
0CCFC2EF3F1E07ECD68D8CE74C734AA5EFF21A1EA1CBCD4151493A318D9A6EC3.pygtex,
15341538
798FDFA05A9542B54FDD2D3C90FFEDD19DB5A2378D936803F2081C0A0A5FC20A.pygtex,
15351539
A0EFF0DAD4E06565647B95526DCF08B03264F5030662F1AEFDB80E787205DC64.pygtex,
1540+
1B8700FBB15D62BD6A053DFD331F13BAD6780C9B890B2179C8FB85A264DC99F3.pygtex,
1541+
833A738861C6FFC808FB3F88C6FF51EEBA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
1542+
696A67E9557FFD9D5BED06FAC16B865EBA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
1543+
B670F2677D205A7707A00470B9DFAD98BA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
1544+
833A738861C6FFC808FB3F88C6FF51EEBA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
1545+
696A67E9557FFD9D5BED06FAC16B865EBA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
1546+
C9B1CA13C1118CBA8A322599EC7A30BBBA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
15361547
2A5E1319C18D5E86561E2A55E3CB82BB4F73A75B5AB1610BEA368A06CA5B9B34.pygtex,
15371548
A8FE800FDFCE014E69DF4F3030A72843BA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
15381549
93E5D1D0E8C4DA0F12F5BAE2C2FCED78BA5FFB870F3277695E59D5E7C5E4ACD6.pygtex,
@@ -1541,4 +1552,4 @@
15411552
2EB12577A06B11263335EFBED8E67EB9707C27D061C92BEE6C2D7894AEB085A0.pygtex,
15421553
684AE6306A2EECB4BA9BF1E553005875C3F364476F7ADDA4E0796B01FAEA1B43.pygtex,
15431554
684AE6306A2EECB4BA9BF1E55300587514FC8E9253423B78F6D68C782EE391E6.pygtex}
1544-
\gdef \@abspage@last{400}
1555+
\gdef \@abspage@last{402}

rust.log

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.12.4) 14 JAN 2023 06:46
1+
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.12.4) 14 JAN 2023 06:59
22
entering extended mode
33
\write18 enabled.
44
%&-line parsing enabled.
@@ -5464,6 +5464,48 @@ A.pygtex)) [390
54645464
(./_minted-rust/A0EFF0DAD4E06565647B95526DCF08B03264F5030662F1AEFDB80E787205DC6
54655465
4.pygtex)) [391
54665466

5467+
]
5468+
\openout4 = `rust.vrb'.
5469+
5470+
(./rust.vrb
5471+
(./_minted-rust/1B8700FBB15D62BD6A053DFD331F13BAD6780C9B890B2179C8FB85A264DC99F
5472+
3.pygtex)) [392
5473+
5474+
]
5475+
\openout4 = `rust.vrb'.
5476+
5477+
(./rust.vrb
5478+
\openout6 = `rust.pyg'.
5479+
5480+
5481+
(./_minted-rust/833A738861C6FFC808FB3F88C6FF51EEBA5FFB870F3277695E59D5E7C5E4ACD
5482+
6.pygtex)
5483+
\openout6 = `rust.pyg'.
5484+
5485+
5486+
(./_minted-rust/696A67E9557FFD9D5BED06FAC16B865EBA5FFB870F3277695E59D5E7C5E4ACD
5487+
6.pygtex)
5488+
\openout6 = `rust.pyg'.
5489+
5490+
5491+
(./_minted-rust/B670F2677D205A7707A00470B9DFAD98BA5FFB870F3277695E59D5E7C5E4ACD
5492+
6.pygtex)
5493+
\openout6 = `rust.pyg'.
5494+
5495+
5496+
(./_minted-rust/833A738861C6FFC808FB3F88C6FF51EEBA5FFB870F3277695E59D5E7C5E4ACD
5497+
6.pygtex)
5498+
\openout6 = `rust.pyg'.
5499+
5500+
5501+
(./_minted-rust/696A67E9557FFD9D5BED06FAC16B865EBA5FFB870F3277695E59D5E7C5E4ACD
5502+
6.pygtex)
5503+
\openout6 = `rust.pyg'.
5504+
5505+
5506+
(./_minted-rust/C9B1CA13C1118CBA8A322599EC7A30BBBA5FFB870F3277695E59D5E7C5E4ACD
5507+
6.pygtex)) [393
5508+
54675509
]
54685510
\openout4 = `rust.vrb'.
54695511

@@ -5479,56 +5521,51 @@ A.pygtex)) [390
54795521

54805522

54815523
(./_minted-rust/93E5D1D0E8C4DA0F12F5BAE2C2FCED78BA5FFB870F3277695E59D5E7C5E4ACD
5482-
6.pygtex)) [392
5524+
6.pygtex)) [394
54835525

54845526
]
54855527
\openout4 = `rust.vrb'.
54865528

54875529
(./rust.vrb
54885530
(./_minted-rust/68CEB6E031967FE0BDE5261537F589E16748D3FC328C9E4CBBB2089A7B510E2
5489-
7.pygtex)) [393
5531+
7.pygtex)) [395
54905532

54915533
]
54925534
\openout4 = `rust.vrb'.
54935535

54945536
(./rust.vrb
54955537
(./_minted-rust/7E15CE4F2E6A9FEA2301EBAB276865107AF691668352F6010254D55AF2EF9A2
5496-
9.pygtex)) [394
5538+
9.pygtex)) [396
54975539

54985540
]
54995541
\openout4 = `rust.vrb'.
55005542

5501-
(./rust.vrb) [395
5543+
(./rust.vrb) [397
55025544

55035545
]
55045546
\openout4 = `rust.vrb'.
55055547

55065548
(./rust.vrb
55075549
(./_minted-rust/2EB12577A06B11263335EFBED8E67EB9707C27D061C92BEE6C2D7894AEB085A
5508-
0.pygtex)) [396
5550+
0.pygtex)) [398
55095551

55105552
]
55115553
\openout4 = `rust.vrb'.
55125554

55135555
(./rust.vrb
55145556
(./_minted-rust/684AE6306A2EECB4BA9BF1E553005875C3F364476F7ADDA4E0796B01FAEA1B4
5515-
3.pygtex)) [397
5557+
3.pygtex)) [399
55165558

55175559
]
55185560
\openout4 = `rust.vrb'.
55195561

55205562
(./rust.vrb
5521-
runsystem(pygmentize -l rust -f latex -P commandprefix=PYG -F tokenmerge -P str
5522-
ipnl=False -P mathescape=True -o _minted-rust/684AE6306A2EECB4BA9BF1E5530058751
5523-
4FC8E9253423B78F6D68C782EE391E6.pygtex ./code/http19.rs)...executed.
5524-
5525-
55265563
(./_minted-rust/684AE6306A2EECB4BA9BF1E55300587514FC8E9253423B78F6D68C782EE391E
5527-
6.pygtex)) [398
5564+
6.pygtex)) [400
55285565

5529-
] [399
5566+
] [401
55305567

5531-
] [400
5568+
] [402
55325569

55335570
]
55345571
\tf@nav=\write8
@@ -5540,9 +5577,6 @@ ipnl=False -P mathescape=True -o _minted-rust/684AE6306A2EECB4BA9BF1E5530058751
55405577
\tf@snm=\write10
55415578
\openout10 = `rust.snm'.
55425579

5543-
runsystem(rm _minted-rust/113A06B107FB92ACAFA4C1AA1A036DFD14FC8E9253423B78F6D68
5544-
C782EE391E6.pygtex)...executed.
5545-
55465580
(./rust.aux)
55475581

55485582
LaTeX Font Warning: Size substitutions with differences
@@ -5557,10 +5591,10 @@ runsystem(rm rust.pyg)...executed.
55575591

55585592
)
55595593
Here is how much of TeX's memory you used:
5560-
31198 strings out of 474968
5561-
802161 string characters out of 5776083
5562-
1089411 words of memory out of 5000000
5563-
48807 multiletter control sequences out of 15000+600000
5594+
31241 strings out of 474968
5595+
804866 string characters out of 5776083
5596+
1091825 words of memory out of 5000000
5597+
48824 multiletter control sequences out of 15000+600000
55645598
485164 words of font info for 86 fonts, out of 8000000 for 9000
55655599
1141 hyphenation exceptions out of 8191
55665600
128i,16n,122p,870b,1087s stack positions out of 10000i,1000n,20000p,200000b,200000s
@@ -5580,10 +5614,10 @@ al/texlive/2022/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy6.pfb></usr/local
55805614
texlive/2022/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt8.pfb></usr/local/te
55815615
xlive/2022/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt9.pfb></usr/local/texl
55825616
ive/2022/texmf-dist/fonts/type1/urw/zapfding/uzdr.pfb>
5583-
Output written on rust.pdf (400 pages, 2491038 bytes).
5617+
Output written on rust.pdf (402 pages, 2496883 bytes).
55845618
PDF statistics:
5585-
11801 PDF objects out of 12825 (max. 8388607)
5586-
11019 compressed objects within 111 object streams
5587-
829 named destinations out of 1000 (max. 500000)
5619+
11855 PDF objects out of 12825 (max. 8388607)
5620+
11071 compressed objects within 111 object streams
5621+
833 named destinations out of 1000 (max. 500000)
55885622
1477 words of extra memory for PDF output out of 10000 (max. 10000000)
55895623

rust.nav

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -851,18 +851,22 @@
851851
\headcommand {\beamer@framepages {397}{397}}
852852
\headcommand {\slideentry {19}{0}{24}{398/398}{}{0}}
853853
\headcommand {\beamer@framepages {398}{398}}
854-
\headcommand {\beamer@sectionpages {375}{398}}
855-
\headcommand {\beamer@subsectionpages {375}{398}}
856-
\headcommand {\sectionentry {20}{Tokio}{399}{Tokio}{0}}
857-
\headcommand {\slideentry {20}{0}{1}{399/399}{}{0}}
854+
\headcommand {\slideentry {19}{0}{25}{399/399}{}{0}}
858855
\headcommand {\beamer@framepages {399}{399}}
859-
\headcommand {\beamer@sectionpages {399}{399}}
860-
\headcommand {\beamer@subsectionpages {399}{399}}
861-
\headcommand {\sectionentry {21}{Acknowledgement}{400}{Acknowledgement}{0}}
862-
\headcommand {\slideentry {21}{0}{1}{400/400}{}{0}}
856+
\headcommand {\slideentry {19}{0}{26}{400/400}{}{0}}
863857
\headcommand {\beamer@framepages {400}{400}}
864-
\headcommand {\beamer@partpages {1}{400}}
865-
\headcommand {\beamer@subsectionpages {400}{400}}
866-
\headcommand {\beamer@sectionpages {400}{400}}
867-
\headcommand {\beamer@documentpages {400}}
868-
\headcommand {\gdef \inserttotalframenumber {400}}
858+
\headcommand {\beamer@sectionpages {375}{400}}
859+
\headcommand {\beamer@subsectionpages {375}{400}}
860+
\headcommand {\sectionentry {20}{Tokio}{401}{Tokio}{0}}
861+
\headcommand {\slideentry {20}{0}{1}{401/401}{}{0}}
862+
\headcommand {\beamer@framepages {401}{401}}
863+
\headcommand {\beamer@sectionpages {401}{401}}
864+
\headcommand {\beamer@subsectionpages {401}{401}}
865+
\headcommand {\sectionentry {21}{Acknowledgement}{402}{Acknowledgement}{0}}
866+
\headcommand {\slideentry {21}{0}{1}{402/402}{}{0}}
867+
\headcommand {\beamer@framepages {402}{402}}
868+
\headcommand {\beamer@partpages {1}{402}}
869+
\headcommand {\beamer@subsectionpages {402}{402}}
870+
\headcommand {\beamer@sectionpages {402}{402}}
871+
\headcommand {\beamer@documentpages {402}}
872+
\headcommand {\gdef \inserttotalframenumber {402}}

rust.pdf

5.71 KB
Binary file not shown.

0 commit comments

Comments
 (0)