Topic: Thread preemption inside RCU protected section
Author: Itaj Sherman <itajsherman@gmail.com>
Date: Sun, 11 Nov 2018 13:34:02 -0800 (PST)
Raw View
------=_Part_226_1985187047.1541972042699
Content-Type: multipart/alternative;
boundary="----=_Part_227_268253849.1541972042699"
------=_Part_227_268253849.1541972042699
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
What happens if a user thread enters a section protected by a locked=20
rcu_reader instance, and gets preempted by the scheduler inside the=20
section?!
When it wakes up, it supposedly continues to run inside the section.
Which means that all rcu protected objects used inside the section have to=
=20
be delayed for a long time until after the thread gets scheduled again.
I want to propose the following suggestion. I really am not sure if it=E2=
=80=99s=20
feasible, it needs compiler and OS support that I=E2=80=99m not sure is alw=
ays=20
available.
A tag or some keyword, let=E2=80=99s say PREEMPTION_BREAK that can mark the=
=20
enclosed {} section of the protected code:
NON_PREEMPTABLE
{
rcu_reader an_rcu_reader;
my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
do_something( *my_rcu_object ); //Some use of protected objects=20
}
The compiler with OS supports needs to make sure of the following:
1. If the execution gets preempted within the section, it is as-if it calls=
=20
an_rcu_reader.unlock() just before the thread got preempted. So that the=20
thread is not considered inside an rcu protected section anymore, during=20
the time it won=E2=80=99t be running. And object it protected can be reclai=
med.
2.When the thread gets scheduled again, it will restart running from the=20
beginning of the section NON_PREEMPTABLE (after stack unwinding), as if an=
=20
exception was thrown and caught at the section level, and then the section=
=20
restarts running (see code below). It doesn=E2=80=99t have to throw immedia=
tely at=20
the preemption position, it can continue running as far as the next time an=
=20
instance of an rcu protected type is used, and throw the exception at the=
=20
next usage.
Basically the compiler has to add code whenever an instance of an rcu=20
protected type is used, to check if within a NON_PREEMPTABLE section, and=
=20
the thread actually has been preempted after the section started, then=20
as-if throw an exception.
while(true)
{
try
{
rcu_reader an_rcu_reader;
my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
/*Suppose the thread gets preempted here. When rescheduled, it can=20
continue running only as far as the next usage of *my_rcu_object inside=20
do_something(), and will =E2=80=9Cthrow std::preemption_exception()=E2=80=
=9D before the=20
object is accessed.*/
do_something( my_rcu_object ); //Some use of protected objects, function=
=20
will dereference it.
}
catch( std::preemption_exception const& )
{
continue; //got preempted, restart section again
}
catch(...)
{
throw;
}
break; //successful, don=E2=80=99t run again.
}
So, the programmer just needs to write the section code as a retryable=20
transaction.
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/88ff3707-f1d9-42ae-ac2d-3e926ff32350%40isocpp.or=
g.
------=_Part_227_268253849.1541972042699
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><span id=3D"docs-internal-guid-8eb902ea-7fff-f67e-ed1b-272=
41e757ff8"><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;">What happens if a user thread enters a section protected by a locked rc=
u_reader instance, and gets preempted by the scheduler inside the section?!=
</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;">When it wakes up, it supposedly continues to run inside the section.</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bott=
om:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, =
0, 0); background-color: transparent; font-variant-numeric: normal; font-va=
riant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"=
>Which means that all rcu protected objects used inside the section have to=
be delayed for a long time until after the thread gets scheduled again.</s=
pan></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-=
bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb=
(0, 0, 0); background-color: transparent; font-variant-numeric: normal; fon=
t-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wr=
ap;">I want to propose the following suggestion. I really am not sure if it=
=E2=80=99s feasible, it needs compiler and OS support that I=E2=80=99m not =
sure is always available.</span></p><br><p dir=3D"ltr" style=3D"line-height=
:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; fo=
nt-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-=
variant-numeric: normal; font-variant-east-asian: normal; vertical-align: b=
aseline; white-space: pre-wrap;">A tag or some keyword, let=E2=80=99s say P=
REEMPTION_BREAK that can mark the enclosed {} section of the protected code=
:</span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;mar=
gin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color:=
rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal;=
font-variant-east-asian: normal; vertical-align: baseline; white-space: pr=
e-wrap;">NON_PREEMPTABLE</span></p><p dir=3D"ltr" style=3D"line-height:1.38=
;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-fa=
mily: Arial; color: rgb(0, 0, 0); background-color: transparent; font-varia=
nt-numeric: normal; font-variant-east-asian: normal; vertical-align: baseli=
ne; white-space: pre-wrap;">{</span></p><p dir=3D"ltr" style=3D"line-height=
:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; fo=
nt-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-=
variant-numeric: normal; font-variant-east-asian: normal; vertical-align: b=
aseline; white-space: pre-wrap;"> =C2=A0rcu_reader an_rcu_reader;</span></p=
><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;=
"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); =
background-color: transparent; font-variant-numeric: normal; font-variant-e=
ast-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> =C2=
=A0my_rcu_type* my_rcu_object =3D =E2=80=A6; </span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fon=
t-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); background-color: tr=
ansparent; font-variant-numeric: normal; font-variant-east-asian: normal; v=
ertical-align: baseline; white-space: pre-wrap;"> =C2=A0do_something( *my_r=
cu_object ); //Some use of protected objects </span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fon=
t-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); background-color: tr=
ansparent; font-variant-numeric: normal; font-variant-east-asian: normal; v=
ertical-align: baseline; white-space: pre-wrap;">}</span></p><br><p dir=3D"=
ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span sty=
le=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); background-=
color: transparent; font-variant-numeric: normal; font-variant-east-asian: =
normal; vertical-align: baseline; white-space: pre-wrap;">The compiler with=
OS supports needs to make sure of the following:</span></p><p dir=3D"ltr" =
style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D=
"background-color: transparent; font-size: 10pt; white-space: pre-wrap; col=
or: rgb(0, 0, 0); font-family: Arial;"><br></span></p><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"back=
ground-color: transparent; font-size: 10pt; white-space: pre-wrap; color: r=
gb(0, 0, 0); font-family: Arial;">1. If the execution gets preempted within=
the section, it is as-if it calls an_rcu_reader.unlock() just before the t=
hread got preempted. So that the thread is not considered inside an rcu pro=
tected section anymore, during the time it won=E2=80=99t be running. And ob=
ject it protected can be reclaimed.</span></p><p dir=3D"ltr" style=3D"line-=
height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"background-co=
lor: transparent; font-size: 10pt; white-space: pre-wrap; color: rgb(0, 0, =
0); font-family: Arial;"><br></span></p><p dir=3D"ltr" style=3D"line-height=
:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"background-color: t=
ransparent; font-size: 10pt; white-space: pre-wrap; color: rgb(0, 0, 0); fo=
nt-family: Arial;">2.When the thread gets scheduled again, it will restart =
running from the beginning of the section NON_PREEMPTABLE (after stack unwi=
nding), as if an exception was thrown and caught at the section level, and =
then the section restarts running (see code below). It doesn=E2=80=99t have=
to throw immediately at the preemption position, it can continue running a=
s far as the next time an instance of an rcu protected type is used, and th=
row the exception at the next usage.</span></p><p dir=3D"ltr" style=3D"line=
-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"background-c=
olor: transparent; font-size: 10pt; white-space: pre-wrap; color: rgb(0, 0,=
0); font-family: Arial;">Basically the compiler has to add code whenever a=
n instance of an rcu protected type is used, to check if within a NON_PREEM=
PTABLE section, and the thread actually has been preempted after the sectio=
n started, then as-if throw an exception.</span></p><br><br><p dir=3D"ltr" =
style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D=
"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); background-color=
: transparent; font-variant-numeric: normal; font-variant-east-asian: norma=
l; vertical-align: baseline; white-space: pre-wrap;">while(true)</span></p>=
<p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"=
><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); b=
ackground-color: transparent; font-variant-numeric: normal; font-variant-ea=
st-asian: normal; vertical-align: baseline; white-space: pre-wrap;">{</span=
></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:=
0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, =
0); background-color: transparent; font-variant-numeric: normal; font-varia=
nt-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> =
=C2=A0try</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt=
;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; co=
lor: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: nor=
mal; font-variant-east-asian: normal; vertical-align: baseline; white-space=
: pre-wrap;"> =C2=A0{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;ma=
rgin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-famil=
y: Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-=
numeric: normal; font-variant-east-asian: normal; vertical-align: baseline;=
white-space: pre-wrap;"> =C2=A0=C2=A0=C2=A0rcu_reader an_rcu_reader;</span=
></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:=
0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, =
0); background-color: transparent; font-variant-numeric: normal; font-varia=
nt-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> =
=C2=A0=C2=A0=C2=A0my_rcu_type* my_rcu_object =3D =E2=80=A6; </span></p><p d=
ir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><sp=
an style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); backg=
round-color: transparent; font-variant-numeric: normal; font-variant-east-a=
sian: normal; vertical-align: baseline; white-space: pre-wrap;"> =C2=A0=C2=
=A0=C2=A0/*Suppose the thread gets preempted here. When rescheduled, it can=
continue running only as far as the next usage of *my_rcu_object inside do=
_something(), and will =E2=80=9Cthrow std::preemption_exception()=E2=80=9D =
before the object is accessed.*/</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt;=
font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; fo=
nt-variant-numeric: normal; font-variant-east-asian: normal; vertical-align=
: baseline; white-space: pre-wrap;"> =C2=A0=C2=A0=C2=A0do_something( my_rcu=
_object ); //Some use of protected objects, function will dereference it.</=
span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bot=
tom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0,=
0, 0); background-color: transparent; font-variant-numeric: normal; font-v=
ariant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;=
"> =C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0p=
t;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; c=
olor: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: no=
rmal; font-variant-east-asian: normal; vertical-align: baseline; white-spac=
e: pre-wrap;"> =C2=A0catch( std::preemption_exception const& )</span></=
p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt=
;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0);=
background-color: transparent; font-variant-numeric: normal; font-variant-=
east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> =C2=
=A0{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;marg=
in-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: =
rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal; =
font-variant-east-asian: normal; vertical-align: baseline; white-space: pre=
-wrap;"> =C2=A0=C2=A0=C2=A0continue; //got preempted, restart section again=
</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;"> =C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial;=
color: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: =
normal; font-variant-east-asian: normal; vertical-align: baseline; white-sp=
ace: pre-wrap;"> =C2=A0catch(...)</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt=
; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;"> =C2=A0{</span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fon=
t-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); background-color: tr=
ansparent; font-variant-numeric: normal; font-variant-east-asian: normal; v=
ertical-align: baseline; white-space: pre-wrap;"> =C2=A0=C2=A0=C2=A0throw;<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bo=
ttom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0=
, 0, 0); background-color: transparent; font-variant-numeric: normal; font-=
variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap=
;"> =C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0=
pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; =
color: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: n=
ormal; font-variant-east-asian: normal; vertical-align: baseline; white-spa=
ce: pre-wrap;"> =C2=A0break; //successful, don=E2=80=99t run again.</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0p=
t;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0)=
; background-color: transparent; font-variant-numeric: normal; font-variant=
-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">}</s=
pan></p><div><span style=3D"font-size: 10pt; font-family: Arial; color: rgb=
(0, 0, 0); background-color: transparent; font-variant-numeric: normal; fon=
t-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wr=
ap;"><br></span></div><div><span style=3D"font-size: 10pt; font-family: Ari=
al; color: rgb(0, 0, 0); background-color: transparent; font-variant-numeri=
c: normal; font-variant-east-asian: normal; vertical-align: baseline; white=
-space: pre-wrap;">So, the programmer just needs to write the section code =
as a retryable transaction.</span></div><div><span style=3D"font-size: 10pt=
; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;"><br></span></div></span></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88ff3707-f1d9-42ae-ac2d-3e926ff32350%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/88ff3707-f1d9-42ae-ac2d-3e926ff32350=
%40isocpp.org</a>.<br />
------=_Part_227_268253849.1541972042699--
------=_Part_226_1985187047.1541972042699--
.
Author: Itaj Sherman <itajsherman@gmail.com>
Date: Sun, 11 Nov 2018 13:40:30 -0800 (PST)
Raw View
------=_Part_893_1051204837.1541972430094
Content-Type: multipart/alternative;
boundary="----=_Part_894_1826598057.1541972430095"
------=_Part_894_1826598057.1541972430095
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
oops, I meant to name the keyword "PREEMPTION_BREAK" instead of=20
"NON_PREEMPTABLE", but I left both of the words in the post.
Also, the purpose is that the reclamation mechanism knows it only has to=20
protect object of threads that are currently running on active processors,=
=20
and not of threads that got preempted. If a thread actually gets blocked by=
=20
the code using a mutex or something, I guess either the developer can take=
=20
care of that, or else it would be possible for the compiler to throw=20
std::preemption_exception() in these cases too.
On Sunday, 11 November 2018 23:34:02 UTC+2, Itaj Sherman wrote:
>
> What happens if a user thread enters a section protected by a locked=20
> rcu_reader instance, and gets preempted by the scheduler inside the=20
> section?!
>
> When it wakes up, it supposedly continues to run inside the section.
>
> Which means that all rcu protected objects used inside the section have t=
o=20
> be delayed for a long time until after the thread gets scheduled again.
>
> I want to propose the following suggestion. I really am not sure if it=E2=
=80=99s=20
> feasible, it needs compiler and OS support that I=E2=80=99m not sure is a=
lways=20
> available.
>
> A tag or some keyword, let=E2=80=99s say PREEMPTION_BREAK that can mark t=
he=20
> enclosed {} section of the protected code:
>
> NON_PREEMPTABLE
>
> {
>
> rcu_reader an_rcu_reader;
>
> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>
> do_something( *my_rcu_object ); //Some use of protected objects=20
>
> }
>
> The compiler with OS supports needs to make sure of the following:
>
>
> 1. If the execution gets preempted within the section, it is as-if it=20
> calls an_rcu_reader.unlock() just before the thread got preempted. So tha=
t=20
> the thread is not considered inside an rcu protected section anymore,=20
> during the time it won=E2=80=99t be running. And object it protected can =
be=20
> reclaimed.
>
>
> 2.When the thread gets scheduled again, it will restart running from the=
=20
> beginning of the section NON_PREEMPTABLE (after stack unwinding), as if a=
n=20
> exception was thrown and caught at the section level, and then the sectio=
n=20
> restarts running (see code below). It doesn=E2=80=99t have to throw immed=
iately at=20
> the preemption position, it can continue running as far as the next time =
an=20
> instance of an rcu protected type is used, and throw the exception at the=
=20
> next usage.
>
> Basically the compiler has to add code whenever an instance of an rcu=20
> protected type is used, to check if within a NON_PREEMPTABLE section, and=
=20
> the thread actually has been preempted after the section started, then=20
> as-if throw an exception.
>
>
> while(true)
>
> {
>
> try
>
> {
>
> rcu_reader an_rcu_reader;
>
> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>
> /*Suppose the thread gets preempted here. When rescheduled, it can=20
> continue running only as far as the next usage of *my_rcu_object inside=
=20
> do_something(), and will =E2=80=9Cthrow std::preemption_exception()=E2=80=
=9D before the=20
> object is accessed.*/
>
> do_something( my_rcu_object ); //Some use of protected objects,=20
> function will dereference it.
>
> }
>
> catch( std::preemption_exception const& )
>
> {
>
> continue; //got preempted, restart section again
>
> }
>
> catch(...)
>
> {
>
> throw;
>
> }
>
> break; //successful, don=E2=80=99t run again.
>
> }
>
> So, the programmer just needs to write the section code as a retryable=20
> transaction.
>
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/5e3f4dc6-6611-420e-91c6-2509525b612d%40isocpp.or=
g.
------=_Part_894_1826598057.1541972430095
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><br></div>oops, I meant to name the keyword "PRE=
EMPTION_BREAK" instead of "NON_PREEMPTABLE", but I left both=
of the words in the post.<br><br>Also, the purpose is that the reclamation=
mechanism knows it only has to protect object of threads that are currentl=
y running on active processors, and not of threads that got preempted. If a=
thread actually gets blocked by the code using a mutex or something, I gue=
ss either the developer can take care of that, or else it would be possible=
for the compiler to throw std::preemption_exception() in these cases too.<=
br><br><br><br>On Sunday, 11 November 2018 23:34:02 UTC+2, Itaj Sherman wr=
ote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><span><p =
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><sp=
an style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-co=
lor:transparent;vertical-align:baseline;white-space:pre-wrap">What happens =
if a user thread enters a section protected by a locked rcu_reader instance=
, and gets preempted by the scheduler inside the section?!</span></p><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color=
:transparent;vertical-align:baseline;white-space:pre-wrap">When it wakes up=
, it supposedly continues to run inside the section.</span></p><p dir=3D"lt=
r" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap">Which means that all =
rcu protected objects used inside the section have to be delayed for a long=
time until after the thread gets scheduled again.</span></p><br><p dir=3D"=
ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span styl=
e=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tra=
nsparent;vertical-align:baseline;white-space:pre-wrap">I want to propose th=
e following suggestion. I really am not sure if it=E2=80=99s feasible, it n=
eeds compiler and OS support that I=E2=80=99m not sure is always available.=
</span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;marg=
in-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,=
0,0);background-color:transparent;vertical-align:baseline;white-space:pre-w=
rap">A tag or some keyword, let=E2=80=99s say PREEMPTION_BREAK that can mar=
k the enclosed {} section of the protected code:</span></p><br><p dir=3D"lt=
r" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap">NON_PREEMPTABLE</span=
></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);backg=
round-color:transparent;vertical-align:baseline;white-space:pre-wrap">{</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);bac=
kground-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =
=C2=A0rcu_reader an_rcu_reader;</span></p><p dir=3D"ltr" style=3D"line-heig=
ht:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;fon=
t-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align=
:baseline;white-space:pre-wrap"> =C2=A0my_rcu_type* my_rcu_object =3D =E2=
=80=A6; </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;=
margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rg=
b(0,0,0);background-color:transparent;vertical-align:baseline;white-space:p=
re-wrap"> =C2=A0do_something( *my_rcu_object ); //Some use of protected obj=
ects </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0=
,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-=
wrap">}</span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color=
:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spac=
e:pre-wrap">The compiler with OS supports needs to make sure of the followi=
ng:</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margi=
n-bottom:0pt"><span style=3D"background-color:transparent;font-size:10pt;wh=
ite-space:pre-wrap;color:rgb(0,0,0);font-family:Arial"><br></span></p><p di=
r=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"background-color:transparent;font-size:10pt;white-space:pre-wrap;=
color:rgb(0,0,0);font-family:Arial">1. If the execution gets preempted with=
in the section, it is as-if it calls an_rcu_reader.unlock() just before the=
thread got preempted. So that the thread is not considered inside an rcu p=
rotected section anymore, during the time it won=E2=80=99t be running. And =
object it protected can be reclaimed.</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"background-c=
olor:transparent;font-size:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-=
family:Arial"><br></span></p><p dir=3D"ltr" style=3D"line-height:1.38;margi=
n-top:0pt;margin-bottom:0pt"><span style=3D"background-color:transparent;fo=
nt-size:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial">2.Whe=
n the thread gets scheduled again, it will restart running from the beginni=
ng of the section NON_PREEMPTABLE (after stack unwinding), as if an excepti=
on was thrown and caught at the section level, and then the section restart=
s running (see code below). It doesn=E2=80=99t have to throw immediately at=
the preemption position, it can continue running as far as the next time a=
n instance of an rcu protected type is used, and throw the exception at the=
next usage.</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"background-color:transparent;font-siz=
e:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial">Basically t=
he compiler has to add code whenever an instance of an rcu protected type i=
s used, to check if within a NON_PREEMPTABLE section, and the thread actual=
ly has been preempted after the section started, then as-if throw an except=
ion.</span></p><br><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;colo=
r:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spa=
ce:pre-wrap">while(true)</span></p><p dir=3D"ltr" style=3D"line-height:1.38=
;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-famil=
y:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseli=
ne;white-space:pre-wrap">{</span></p><p dir=3D"ltr" style=3D"line-height:1.=
38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-fam=
ily:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:base=
line;white-space:pre-wrap"> =C2=A0try</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10=
pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical=
-align:baseline;white-space:pre-wrap"> =C2=A0{</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent=
;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0rcu_reade=
r an_rcu_reader;</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-=
top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;=
color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white=
-space:pre-wrap"> =C2=A0=C2=A0=C2=A0my_rcu_type* my_rcu_object =3D =E2=80=
=A6; </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0=
,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-=
wrap"> =C2=A0=C2=A0=C2=A0/*Suppose the thread gets preempted here. When res=
cheduled, it can continue running only as far as the next usage of *my_rcu_=
object inside do_something(), and will =E2=80=9Cthrow std::preemption_excep=
tion()=E2=80=9D before the object is accessed.*/</span></p><p dir=3D"ltr" s=
tyle=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"f=
ont-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transpare=
nt;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0do_some=
thing( my_rcu_object ); //Some use of protected objects, function will dere=
ference it.</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color=
:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spac=
e:pre-wrap"> =C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;mar=
gin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Ar=
ial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;w=
hite-space:pre-wrap"> =C2=A0catch( std::preemption_exception const& )</=
span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bot=
tom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);b=
ackground-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =
=C2=A0{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;m=
argin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb=
(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pr=
e-wrap"> =C2=A0=C2=A0=C2=A0continue; //got preempted, restart section again=
</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-b=
ottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0)=
;background-color:transparent;vertical-align:baseline;white-space:pre-wrap"=
> =C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:r=
gb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:=
pre-wrap"> =C2=A0catch(...)</span></p><p dir=3D"ltr" style=3D"line-height:1=
..38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-fa=
mily:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:bas=
eline;white-space:pre-wrap"> =C2=A0{</span></p><p dir=3D"ltr" style=3D"line=
-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10p=
t;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-=
align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0throw;</span></p><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0}</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);bac=
kground-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =
=C2=A0break; //successful, don=E2=80=99t run again.</span></p><p dir=3D"ltr=
" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap">}</span></p><div><spa=
n style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-col=
or:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span></d=
iv><div><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);ba=
ckground-color:transparent;vertical-align:baseline;white-space:pre-wrap">So=
, the programmer just needs to write the section code as a retryable transa=
ction.</span></div><div><span style=3D"font-size:10pt;font-family:Arial;col=
or:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-sp=
ace:pre-wrap"><br></span></div></span></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/5e3f4dc6-6611-420e-91c6-2509525b612d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5e3f4dc6-6611-420e-91c6-2509525b612d=
%40isocpp.org</a>.<br />
------=_Part_894_1826598057.1541972430095--
------=_Part_893_1051204837.1541972430094--
.
Author: Anthony Williams <anthony.ajw@gmail.com>
Date: Mon, 12 Nov 2018 06:52:51 +0000
Raw View
On 11/11/2018 21:34, Itaj Sherman wrote:
> What happens if a user thread enters a section protected by a locked
> rcu_reader instance, and gets preempted by the scheduler inside the
> section?!
Nothing.
> When it wakes up, it supposedly continues to run inside the section.
>=20
> Which means that all rcu protected objects used inside the section have
> to be delayed for a long time until after the thread gets scheduled again=
..
Yes.
> I want to propose the following suggestion. I really am not sure if it=E2=
=80=99s
> feasible, it needs compiler and OS support that I=E2=80=99m not sure is a=
lways
> available.
It is unnecessary. RCU is designed to cope with long grace periods
before reclamation, precisely due to issues like this.
At kernel level, you already have the ability to mark sections of code
non-preemptable.
At user level, this would require the ability to run code when the OS is
preempting you (in order to remove the RCU read tag), which is against
the very concept of preemption, so it is not implementable.
Cheers,
Anthony
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/1f8aee48-8a20-0f42-b180-bf1d31a47530%40gmail.com=
..
.
Author: Itaj Sherman <itajsherman@gmail.com>
Date: Mon, 12 Nov 2018 09:50:55 -0800 (PST)
Raw View
------=_Part_563_890718201.1542045055306
Content-Type: multipart/alternative;
boundary="----=_Part_564_112392111.1542045055307"
------=_Part_564_112392111.1542045055307
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Monday, 12 November 2018 08:52:56 UTC+2, Anthony Williams wrote:
>
> On 11/11/2018 21:34, Itaj Sherman wrote:=20
> > What happens if a user thread enters a section protected by a locked=20
> > rcu_reader instance, and gets preempted by the scheduler inside the=20
> > section?!=20
>
> Nothing.=20
>
> > When it wakes up, it supposedly continues to run inside the section.=20
> >=20
> > Which means that all rcu protected objects used inside the section have=
=20
> > to be delayed for a long time until after the thread gets scheduled=20
> again.=20
>
> Yes.=20
>
> > I want to propose the following suggestion. I really am not sure if it=
=E2=80=99s=20
> > feasible, it needs compiler and OS support that I=E2=80=99m not sure is=
always=20
> > available.=20
>
> It is unnecessary. RCU is designed to cope with long grace periods=20
> before reclamation, precisely due to issues like this.=20
>
>
Well, I wish it were possible, this could decrease the grace period by
a large factor and simplify the worry about the amount of retired objects.
If a thread with very low priority does get preempted in section, you have=
=20
to do something to resolve it.
You force the developer to increase threads=E2=80=99 priorities just to mak=
e sure=20
they run in a manner that doesn=E2=80=99t stall reclamation. In cases where=
the=20
developer wouldn=E2=80=99t otherwise wish to do so.
If the reclamation mechanism is going to automatically increase priorities=
=20
for threads that got preempted in protected sections, it will need about=20
the same sort of OS support.
=20
> At kernel level, you already have the ability to mark sections of code=20
> non-preemptable.=20
>
> At user level, this would require the ability to run code when the OS is=
=20
> preempting you (in order to remove the RCU read tag), which is against=20
> the very concept of preemption, so it is not implementable.=20
>
>
Technically you don=E2=80=99t have to run code exactly on the thread when i=
t gets=20
preempted. But then the reclamation mechanism whenever it runs needs to=20
be able to query about it and recognize that a thread got preempted while
in protected section.
Or else if it is assumed that all threads in the system use such=20
PREEMPTION_BREAK,=20
it can assume that only currently active processors could be in protected=
=20
sections.
When the thread gets rescheduled, it will have to be able to run some
code before the execution continues. It has to do something to make
sure that the execution flow eventually changes before the next access
to any protected object. And the OS would have to support some
interrupt handler for that, or some more specialized support.=20
Otherwise the reclamation mechanism would have to do that,=20
maybe by somehow directly or indirectly changing the execution position of=
=20
the
preempted thread to a separate code that is compiled for this case.
It doesn=E2=80=99t have to be enforced that a preempted section must be res=
tarted,=20
but it=20
could at least be known that the implementation is allowed to do it.
=20
> Cheers,=20
>
> Anthony=20
>
regards,
itaj=20
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/11d315a5-f4ea-428b-b060-7d6e02f39a82%40isocpp.or=
g.
------=_Part_564_112392111.1542045055307
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, 12 November 2018 08:52:56 UTC+2, Anthon=
y Williams wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 11/11/201=
8 21:34, Itaj Sherman wrote:
<br>> What happens if a user thread enters a section protected by a lock=
ed
<br>> rcu_reader instance, and gets preempted by the scheduler inside th=
e
<br>> section?!
<br>
<br>Nothing.
<br>
<br>> When it wakes up, it supposedly continues to run inside the sectio=
n.
<br>>=20
<br>> Which means that all rcu protected objects used inside the section=
have
<br>> to be delayed for a long time until after the thread gets schedule=
d again.
<br>
<br>Yes.
<br>
<br>> I want to propose the following suggestion. I really am not sure i=
f it=E2=80=99s
<br>> feasible, it needs compiler and OS support that I=E2=80=99m not su=
re is always
<br>> available.
<br>
<br>It is unnecessary. RCU is designed to cope with long grace periods
<br>before reclamation, precisely due to issues like this.
<br>
<br></blockquote><div><br></div><div><span id=3D"docs-internal-guid-83d4a24=
b-7fff-235c-8577-4bf31ca0be9a"><p dir=3D"ltr" style=3D"line-height:1.656;ma=
rgin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-famil=
y: Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-=
numeric: normal; font-variant-east-asian: normal; vertical-align: baseline;=
white-space: pre-wrap;">Well, I wish it were possible, this could decrease=
the grace period by</span></p><p dir=3D"ltr" style=3D"line-height:1.656;ma=
rgin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-famil=
y: Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-=
numeric: normal; font-variant-east-asian: normal; vertical-align: baseline;=
white-space: pre-wrap;">a large factor and simplify the worry about the am=
ount of retired objects.</span></p><br><p dir=3D"ltr" style=3D"line-height:=
1.656;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; fo=
nt-family: Arial; color: rgb(0, 0, 0); background-color: transparent; font-=
variant-numeric: normal; font-variant-east-asian: normal; vertical-align: b=
aseline; white-space: pre-wrap;">If a thread with very low priority does ge=
t preempted in section, you have </span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.656;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10p=
t; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; =
font-variant-numeric: normal; font-variant-east-asian: normal; vertical-ali=
gn: baseline; white-space: pre-wrap;">to do something to resolve it.</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;margin-bottom:=
0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, =
0); background-color: transparent; font-variant-numeric: normal; font-varia=
nt-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Yo=
u force the developer to increase threads=E2=80=99 priorities just to make =
sure </span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;ma=
rgin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color=
: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal=
; font-variant-east-asian: normal; vertical-align: baseline; white-space: p=
re-wrap;">they run in a manner that doesn=E2=80=99t stall reclamation. In c=
ases where the </span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-=
top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Ar=
ial; color: rgb(0, 0, 0); background-color: transparent; font-variant-numer=
ic: normal; font-variant-east-asian: normal; vertical-align: baseline; whit=
e-space: pre-wrap;">developer wouldn=E2=80=99t otherwise wish to do so.</sp=
an></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;">If the reclamation mechanism is going to automatically increase priorit=
ies </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;marg=
in-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: =
rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal; =
font-variant-east-asian: normal; vertical-align: baseline; white-space: pre=
-wrap;">for threads that got preempted in protected sections, it will need =
about </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;ma=
rgin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color=
: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal=
; font-variant-east-asian: normal; vertical-align: baseline; white-space: p=
re-wrap;">the same sort of OS support.</span></p><div><br></div></span></di=
v><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">At kernel l=
evel, you already have the ability to mark sections of code
<br>non-preemptable.
<br>
<br>At user level, this would require the ability to run code when the OS i=
s
<br>preempting you (in order to remove the RCU read tag), which is against
<br>the very concept of preemption, so it is not implementable.
<br>
<br></blockquote><div><br></div><div><span id=3D"docs-internal-guid-e2f3458=
b-7fff-0975-0950-15458c6076f7"><p dir=3D"ltr" style=3D"line-height:1.656;ma=
rgin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-famil=
y: Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-=
numeric: normal; font-variant-east-asian: normal; vertical-align: baseline;=
white-space: pre-wrap;">Technically you don=E2=80=99t have to run code exa=
ctly on the thread when it gets </span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.656;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt=
; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;">preempted. But then the reclamation me=
chanism whenever it runs needs to </span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.656;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10=
pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent;=
font-variant-numeric: normal; font-variant-east-asian: normal; vertical-al=
ign: baseline; white-space: pre-wrap;">be able to query about it and recogn=
ize that a thread got preempted while</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.656;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:=
10pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transpare=
nt; font-variant-numeric: normal; font-variant-east-asian: normal; vertical=
-align: baseline; white-space: pre-wrap;">in protected section.</span></p><=
p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;margin-bottom:0pt;"=
><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); b=
ackground-color: transparent; font-variant-numeric: normal; font-variant-ea=
st-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Or else=
if it is assumed that all threads in the system use such PREEMPTION_BREAK,=
</span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;margin=
-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rg=
b(0, 0, 0); background-color: transparent; font-variant-numeric: normal; fo=
nt-variant-east-asian: normal; vertical-align: baseline; white-space: pre-w=
rap;">it can assume that only currently active processors could be in prote=
cted sections.</span></p><br><p dir=3D"ltr" style=3D"line-height:1.656;marg=
in-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family:=
Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-nu=
meric: normal; font-variant-east-asian: normal; vertical-align: baseline; w=
hite-space: pre-wrap;">When the thread gets rescheduled, it will have to be=
able to run some</span></p><p dir=3D"ltr" style=3D"line-height:1.656;margi=
n-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: =
Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-num=
eric: normal; font-variant-east-asian: normal; vertical-align: baseline; wh=
ite-space: pre-wrap;">code before the execution continues. It has to do som=
ething to make</span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-t=
op:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Ari=
al; color: rgb(0, 0, 0); background-color: transparent; font-variant-numeri=
c: normal; font-variant-east-asian: normal; vertical-align: baseline; white=
-space: pre-wrap;">sure that the execution flow eventually changes before t=
he next access</span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-t=
op:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Ari=
al; color: rgb(0, 0, 0); background-color: transparent; font-variant-numeri=
c: normal; font-variant-east-asian: normal; vertical-align: baseline; white=
-space: pre-wrap;">to any protected object. And the OS would have to suppor=
t some</span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;m=
argin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; colo=
r: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: norma=
l; font-variant-east-asian: normal; vertical-align: baseline; white-space: =
pre-wrap;">interrupt handler for that, or some more specialized support. </=
span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;margin-bo=
ttom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0=
, 0, 0); background-color: transparent; font-variant-numeric: normal; font-=
variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap=
;">Otherwise the reclamation mechanism would have to do that, </span></p><p=
dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;margin-bottom:0pt;">=
<span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); ba=
ckground-color: transparent; font-variant-numeric: normal; font-variant-eas=
t-asian: normal; vertical-align: baseline; white-space: pre-wrap;">maybe by=
somehow directly or indirectly changing the execution position of the</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;margin-botto=
m:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0=
, 0); background-color: transparent; font-variant-numeric: normal; font-var=
iant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">=
preempted thread to a separate code that is compiled for this case.</span><=
/p><br><p dir=3D"ltr" style=3D"line-height:1.656;margin-top:0pt;margin-bott=
om:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, =
0, 0); background-color: transparent; font-variant-numeric: normal; font-va=
riant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"=
>It doesn=E2=80=99t have to be enforced that a preempted section must be re=
started, but it </span></p><p dir=3D"ltr" style=3D"line-height:1.656;margin=
-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: A=
rial; color: rgb(0, 0, 0); background-color: transparent; font-variant-nume=
ric: normal; font-variant-east-asian: normal; vertical-align: baseline; whi=
te-space: pre-wrap;">could at least be known that the implementation is all=
owed to do it.</span></p><div>=C2=A0<br></div></span></div><blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;">Cheers,
<br>
<br>Anthony
<br></blockquote><div><br></div><div>regards,</div><div>itaj=C2=A0</div></d=
iv>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/11d315a5-f4ea-428b-b060-7d6e02f39a82%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/11d315a5-f4ea-428b-b060-7d6e02f39a82=
%40isocpp.org</a>.<br />
------=_Part_564_112392111.1542045055307--
------=_Part_563_890718201.1542045055306--
.
Author: Itaj Sherman <itajsherman@gmail.com>
Date: Mon, 12 Nov 2018 10:46:25 -0800 (PST)
Raw View
------=_Part_2114_1434057186.1542048385600
Content-Type: multipart/alternative;
boundary="----=_Part_2115_1225564450.1542048385600"
------=_Part_2115_1225564450.1542048385600
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Sunday, 11 November 2018 23:40:30 UTC+2, Itaj Sherman wrote:
>
>
> oops, I meant to name the keyword "PREEMPTION_BREAK" instead of=20
> "NON_PREEMPTABLE", but I left both of the words in the post.
>
> Also, the purpose is that the reclamation mechanism knows it only has to=
=20
> protect object of threads that are currently running on active processors=
,=20
> and not of threads that got preempted. If a thread actually gets blocked =
by=20
> the code using a mutex or something, I guess either the developer can tak=
e=20
> care of that, or else it would be possible for the compiler to throw=20
> std::preemption_exception() in these cases too.
>
>
>
> On Sunday, 11 November 2018 23:34:02 UTC+2, Itaj Sherman wrote:
>>
>> What happens if a user thread enters a section protected by a locked=20
>> rcu_reader instance, and gets preempted by the scheduler inside the=20
>> section?!
>>
>> When it wakes up, it supposedly continues to run inside the section.
>>
>> Which means that all rcu protected objects used inside the section have=
=20
>> to be delayed for a long time until after the thread gets scheduled agai=
n.
>>
>> I want to propose the following suggestion. I really am not sure if it=
=E2=80=99s=20
>> feasible, it needs compiler and OS support that I=E2=80=99m not sure is =
always=20
>> available.
>>
>> A tag or some keyword, let=E2=80=99s say PREEMPTION_BREAK that can mark =
the=20
>> enclosed {} section of the protected code:
>>
>> NON_PREEMPTABLE
>>
>> {
>>
>> rcu_reader an_rcu_reader;
>>
>> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>>
>> do_something( *my_rcu_object ); //Some use of protected objects=20
>>
>> }
>>
>> The compiler with OS supports needs to make sure of the following:
>>
>>
>> 1. If the execution gets preempted within the section, it is as-if it=20
>> calls an_rcu_reader.unlock() just before the thread got preempted. So th=
at=20
>> the thread is not considered inside an rcu protected section anymore,=20
>> during the time it won=E2=80=99t be running. And object it protected can=
be=20
>> reclaimed.
>>
>>
>> 2.When the thread gets scheduled again, it will restart running from the=
=20
>> beginning of the section NON_PREEMPTABLE (after stack unwinding), as if =
an=20
>> exception was thrown and caught at the section level, and then the secti=
on=20
>> restarts running (see code below). It doesn=E2=80=99t have to throw imme=
diately at=20
>> the preemption position, it can continue running as far as the next time=
an=20
>> instance of an rcu protected type is used, and throw the exception at th=
e=20
>> next usage.
>>
>> Basically the compiler has to add code whenever an instance of an rcu=20
>> protected type is used, to check if within a NON_PREEMPTABLE section, an=
d=20
>> the thread actually has been preempted after the section started, then=
=20
>> as-if throw an exception.
>>
>>
>> while(true)
>>
>> {
>>
>> try
>>
>> {
>>
>> rcu_reader an_rcu_reader;
>>
>> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>>
>> /*Suppose the thread gets preempted here. When rescheduled, it can=20
>> continue running only as far as the next usage of *my_rcu_object inside=
=20
>> do_something(), and will =E2=80=9Cthrow std::preemption_exception()=E2=
=80=9D before the=20
>> object is accessed.*/
>>
>> do_something( my_rcu_object ); //Some use of protected objects,=20
>> function will dereference it.
>>
>> }
>>
>> catch( std::preemption_exception const& )
>>
>> {
>>
>> continue; //got preempted, restart section again
>>
>> }
>>
>> catch(...)
>>
>> {
>>
>> throw;
>>
>> }
>>
>> break; //successful, don=E2=80=99t run again.
>>
>> }
>>
>> So, the programmer just needs to write the section code as a retryable=
=20
>> transaction.
>>
>>
If there's any access to protected objects inside noexcept functions, it's=
=20
going to require a
lot of compiler work.
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/40a8af12-443c-4328-95b0-77348a2e85e7%40isocpp.or=
g.
------=_Part_2115_1225564450.1542048385600
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, 11 November 2018 23:40:30 UTC+2, Itaj S=
herman wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
><div><br></div>oops, I meant to name the keyword "PREEMPTION_BREAK&qu=
ot; instead of "NON_PREEMPTABLE", but I left both of the words in=
the post.<br><br>Also, the purpose is that the reclamation mechanism knows=
it only has to protect object of threads that are currently running on act=
ive processors, and not of threads that got preempted. If a thread actually=
gets blocked by the code using a mutex or something, I guess either the de=
veloper can take care of that, or else it would be possible for the compile=
r to throw std::preemption_exception() in these cases too.<br><br><br><br>O=
n Sunday, 11 November 2018 23:34:02 UTC+2, Itaj Sherman wrote:<blockquote =
class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #=
ccc solid;padding-left:1ex"><div dir=3D"ltr"><span><p dir=3D"ltr" style=3D"=
line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size=
:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;verti=
cal-align:baseline;white-space:pre-wrap">What happens if a user thread ente=
rs a section protected by a locked rcu_reader instance, and gets preempted =
by the scheduler inside the section?!</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10=
pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical=
-align:baseline;white-space:pre-wrap">When it wakes up, it supposedly conti=
nues to run inside the section.</span></p><p dir=3D"ltr" style=3D"line-heig=
ht:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;fon=
t-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align=
:baseline;white-space:pre-wrap">Which means that all rcu protected objects =
used inside the section have to be delayed for a long time until after the =
thread gets scheduled again.</span></p><br><p dir=3D"ltr" style=3D"line-hei=
ght:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;fo=
nt-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-alig=
n:baseline;white-space:pre-wrap">I want to propose the following suggestion=
.. I really am not sure if it=E2=80=99s feasible, it needs compiler and OS s=
upport that I=E2=80=99m not sure is always available.</span></p><br><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color=
:transparent;vertical-align:baseline;white-space:pre-wrap">A tag or some ke=
yword, let=E2=80=99s say PREEMPTION_BREAK that can mark the enclosed {} sec=
tion of the protected code:</span></p><br><p dir=3D"ltr" style=3D"line-heig=
ht:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;fon=
t-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align=
:baseline;white-space:pre-wrap">NON_PREEMPTABLE</span></p><p dir=3D"ltr" st=
yle=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"fo=
nt-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparen=
t;vertical-align:baseline;white-space:pre-wrap">{</span></p><p dir=3D"ltr" =
style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"=
font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transpar=
ent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0rcu_reader an_rcu_=
reader;</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;m=
argin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb=
(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pr=
e-wrap"> =C2=A0my_rcu_type* my_rcu_object =3D =E2=80=A6; </span></p><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color=
:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0do_someth=
ing( *my_rcu_object ); //Some use of protected objects </span></p><p dir=3D=
"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span sty=
le=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tr=
ansparent;vertical-align:baseline;white-space:pre-wrap">}</span></p><br><p =
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><sp=
an style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-co=
lor:transparent;vertical-align:baseline;white-space:pre-wrap">The compiler =
with OS supports needs to make sure of the following:</span></p><p dir=3D"l=
tr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"background-color:transparent;font-size:10pt;white-space:pre-wrap;color:=
rgb(0,0,0);font-family:Arial"><br></span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"background-colo=
r:transparent;font-size:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-fam=
ily:Arial">1. If the execution gets preempted within the section, it is as-=
if it calls an_rcu_reader.unlock() just before the thread got preempted. So=
that the thread is not considered inside an rcu protected section anymore,=
during the time it won=E2=80=99t be running. And object it protected can b=
e reclaimed.</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"background-color:transparent;font-siz=
e:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial"><br></span>=
</p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"background-color:transparent;font-size:10pt;white-space:=
pre-wrap;color:rgb(0,0,0);font-family:Arial">2.When the thread gets schedul=
ed again, it will restart running from the beginning of the section NON_PRE=
EMPTABLE (after stack unwinding), as if an exception was thrown and caught =
at the section level, and then the section restarts running (see code below=
). It doesn=E2=80=99t have to throw immediately at the preemption position,=
it can continue running as far as the next time an instance of an rcu prot=
ected type is used, and throw the exception at the next usage.</span></p><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"background-color:transparent;font-size:10pt;white-space:pre-wr=
ap;color:rgb(0,0,0);font-family:Arial">Basically the compiler has to add co=
de whenever an instance of an rcu protected type is used, to check if withi=
n a NON_PREEMPTABLE section, and the thread actually has been preempted aft=
er the section started, then as-if throw an exception.</span></p><br><br><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap">while(true)<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);=
background-color:transparent;vertical-align:baseline;white-space:pre-wrap">=
{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0=
);background-color:transparent;vertical-align:baseline;white-space:pre-wrap=
"> =C2=A0try</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;colo=
r:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spa=
ce:pre-wrap"> =C2=A0{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:A=
rial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;=
white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0rcu_reader an_rcu_reader;</span></=
p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt=
"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);backgrou=
nd-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=
=C2=A0=C2=A0my_rcu_type* my_rcu_object =3D =E2=80=A6; </span></p><p dir=3D"=
ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span styl=
e=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tra=
nsparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0/=
*Suppose the thread gets preempted here. When rescheduled, it can continue =
running only as far as the next usage of *my_rcu_object inside do_something=
(), and will =E2=80=9Cthrow std::preemption_exception()=E2=80=9D before the=
object is accessed.*/</span></p><p dir=3D"ltr" style=3D"line-height:1.38;m=
argin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:=
Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline=
;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0do_something( my_rcu_object ); //=
Some use of protected objects, function will dereference it.</span></p><p d=
ir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><spa=
n style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-col=
or:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0}</span=
></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);backg=
round-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=
=A0catch( std::preemption_exception const& )</span></p><p dir=3D"ltr" s=
tyle=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"f=
ont-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transpare=
nt;vertical-align:baseline;white-space:pre-wrap"> =C2=A0{</span></p><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color=
:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=
=A0continue; //got preempted, restart section again</span></p><p dir=3D"ltr=
" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0}</span></p><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0catch=
(...)</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0=
,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-=
wrap"> =C2=A0{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-to=
p:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;co=
lor:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-s=
pace:pre-wrap"> =C2=A0=C2=A0=C2=A0throw;</span></p><p dir=3D"ltr" style=3D"=
line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size=
:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;verti=
cal-align:baseline;white-space:pre-wrap"> =C2=A0}</span></p><p dir=3D"ltr" =
style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"=
font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transpar=
ent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0break; //successfu=
l, don=E2=80=99t run again.</span></p><p dir=3D"ltr" style=3D"line-height:1=
..38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-fa=
mily:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:bas=
eline;white-space:pre-wrap">}</span></p><div><span style=3D"font-size:10pt;=
font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-al=
ign:baseline;white-space:pre-wrap"><br></span></div><div><span style=3D"fon=
t-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent=
;vertical-align:baseline;white-space:pre-wrap">So, the programmer just need=
s to write the section code as a retryable transaction.</span></div><div><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span><=
/div></span></div></blockquote></div></blockquote><div><br></div><div>If th=
ere's any access to protected objects inside noexcept functions, it'=
;s going to require a</div><div>lot of compiler work.</div><div><br></div><=
/div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/40a8af12-443c-4328-95b0-77348a2e85e7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/40a8af12-443c-4328-95b0-77348a2e85e7=
%40isocpp.org</a>.<br />
------=_Part_2115_1225564450.1542048385600--
------=_Part_2114_1434057186.1542048385600--
.
Author: Itaj Sherman <itajsherman@gmail.com>
Date: Tue, 13 Nov 2018 19:53:12 -0800 (PST)
Raw View
------=_Part_2838_805128665.1542167592525
Content-Type: multipart/alternative;
boundary="----=_Part_2839_1652106898.1542167592525"
------=_Part_2839_1652106898.1542167592525
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Sunday, 11 November 2018 23:34:02 UTC+2, Itaj Sherman wrote:
>
> What happens if a user thread enters a section protected by a locked=20
> rcu_reader instance, and gets preempted by the scheduler inside the=20
> section?!
>
> When it wakes up, it supposedly continues to run inside the section.
>
> Which means that all rcu protected objects used inside the section have t=
o=20
> be delayed for a long time until after the thread gets scheduled again.
>
> I want to propose the following suggestion. I really am not sure if it=E2=
=80=99s=20
> feasible, it needs compiler and OS support that I=E2=80=99m not sure is a=
lways=20
> available.
>
> A tag or some keyword, let=E2=80=99s say PREEMPTION_BREAK that can mark t=
he=20
> enclosed {} section of the protected code:
>
> NON_PREEMPTABLE
>
> {
>
> rcu_reader an_rcu_reader;
>
> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>
> do_something( *my_rcu_object ); //Some use of protected objects=20
>
> }
>
> The compiler with OS supports needs to make sure of the following:
>
>
> 1. If the execution gets preempted within the section, it is as-if it=20
> calls an_rcu_reader.unlock() just before the thread got preempted. So tha=
t=20
> the thread is not considered inside an rcu protected section anymore,=20
> during the time it won=E2=80=99t be running. And object it protected can =
be=20
> reclaimed.
>
>
> 2.When the thread gets scheduled again, it will restart running from the=
=20
> beginning of the section NON_PREEMPTABLE (after stack unwinding), as if a=
n=20
> exception was thrown and caught at the section level, and then the sectio=
n=20
> restarts running (see code below). It doesn=E2=80=99t have to throw immed=
iately at=20
> the preemption position, it can continue running as far as the next time =
an=20
> instance of an rcu protected type is used, and throw the exception at the=
=20
> next usage.
>
> Basically the compiler has to add code whenever an instance of an rcu=20
> protected type is used, to check if within a NON_PREEMPTABLE section, and=
=20
> the thread actually has been preempted after the section started, then=20
> as-if throw an exception.
>
>
> while(true)
>
> {
>
> try
>
> {
>
> rcu_reader an_rcu_reader;
>
> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>
> /*Suppose the thread gets preempted here. When rescheduled, it can=20
> continue running only as far as the next usage of *my_rcu_object inside=
=20
> do_something(), and will =E2=80=9Cthrow std::preemption_exception()=E2=80=
=9D before the=20
> object is accessed.*/
>
> do_something( my_rcu_object ); //Some use of protected objects,=20
> function will dereference it.
>
> }
>
> catch( std::preemption_exception const& )
>
> {
>
> continue; //got preempted, restart section again
>
> }
>
> catch(...)
>
> {
>
> throw;
>
> }
>
> break; //successful, don=E2=80=99t run again.
>
> }
>
> So, the programmer just needs to write the section code as a retryable=20
> transaction.
>
>
Well, I guess breaking the protected section isn=E2=80=99t going to be fea=
sible.
How about then enabling the reclamation mechanism to first recognize which=
=20
threads have been preempted inside a protected section, and then get a list=
=20
of pointers to the specific protected objects that this preempted thread=20
accessed.
Then it can add just these pointers to a separate protected list and=20
terminate the grace period.
I guess the thread will have to store all the protected types pointers that=
=20
it accesses in a buffer (unique to each thread). Then the reclamation=20
mechanism will have to read it - I guess it has to know that it=20
strongly-happens-after the preempted thread has been preempted, or maybe=20
send a SIGUSR1 to the thread.
Is that possible?
itaj
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/9f6cb880-21cd-442c-a449-17f88c932db8%40isocpp.or=
g.
------=_Part_2839_1652106898.1542167592525
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, 11 November 2018 23:34:02 UTC+2, Itaj S=
herman wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
><span><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);bac=
kground-color:transparent;vertical-align:baseline;white-space:pre-wrap">Wha=
t happens if a user thread enters a section protected by a locked rcu_reade=
r instance, and gets preempted by the scheduler inside the section?!</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);backgr=
ound-color:transparent;vertical-align:baseline;white-space:pre-wrap">When i=
t wakes up, it supposedly continues to run inside the section.</span></p><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap">Which means =
that all rcu protected objects used inside the section have to be delayed f=
or a long time until after the thread gets scheduled again.</span></p><br><=
p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-=
color:transparent;vertical-align:baseline;white-space:pre-wrap">I want to p=
ropose the following suggestion. I really am not sure if it=E2=80=99s feasi=
ble, it needs compiler and OS support that I=E2=80=99m not sure is always a=
vailable.</span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top=
:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;col=
or:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-sp=
ace:pre-wrap">A tag or some keyword, let=E2=80=99s say PREEMPTION_BREAK tha=
t can mark the enclosed {} section of the protected code:</span></p><br><p =
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><sp=
an style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-co=
lor:transparent;vertical-align:baseline;white-space:pre-wrap">NON_PREEMPTAB=
LE</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,=
0);background-color:transparent;vertical-align:baseline;white-space:pre-wra=
p">{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;marg=
in-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,=
0,0);background-color:transparent;vertical-align:baseline;white-space:pre-w=
rap"> =C2=A0rcu_reader an_rcu_reader;</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10=
pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical=
-align:baseline;white-space:pre-wrap"> =C2=A0my_rcu_type* my_rcu_object =3D=
=E2=80=A6; </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;colo=
r:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spa=
ce:pre-wrap"> =C2=A0do_something( *my_rcu_object ); //Some use of protected=
objects </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:r=
gb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:=
pre-wrap">}</span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-t=
op:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;c=
olor:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-=
space:pre-wrap">The compiler with OS supports needs to make sure of the fol=
lowing:</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;m=
argin-bottom:0pt"><span style=3D"background-color:transparent;font-size:10p=
t;white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial"><br></span></p><=
p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"background-color:transparent;font-size:10pt;white-space:pre-w=
rap;color:rgb(0,0,0);font-family:Arial">1. If the execution gets preempted =
within the section, it is as-if it calls an_rcu_reader.unlock() just before=
the thread got preempted. So that the thread is not considered inside an r=
cu protected section anymore, during the time it won=E2=80=99t be running. =
And object it protected can be reclaimed.</span></p><p dir=3D"ltr" style=3D=
"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"backgrou=
nd-color:transparent;font-size:10pt;white-space:pre-wrap;color:rgb(0,0,0);f=
ont-family:Arial"><br></span></p><p dir=3D"ltr" style=3D"line-height:1.38;m=
argin-top:0pt;margin-bottom:0pt"><span style=3D"background-color:transparen=
t;font-size:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial">2=
..When the thread gets scheduled again, it will restart running from the beg=
inning of the section NON_PREEMPTABLE (after stack unwinding), as if an exc=
eption was thrown and caught at the section level, and then the section res=
tarts running (see code below). It doesn=E2=80=99t have to throw immediatel=
y at the preemption position, it can continue running as far as the next ti=
me an instance of an rcu protected type is used, and throw the exception at=
the next usage.</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-=
top:0pt;margin-bottom:0pt"><span style=3D"background-color:transparent;font=
-size:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial">Basical=
ly the compiler has to add code whenever an instance of an rcu protected ty=
pe is used, to check if within a NON_PREEMPTABLE section, and the thread ac=
tually has been preempted after the section started, then as-if throw an ex=
ception.</span></p><br><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-=
top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;=
color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white=
-space:pre-wrap">while(true)</span></p><p dir=3D"ltr" style=3D"line-height:=
1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-f=
amily:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:ba=
seline;white-space:pre-wrap">{</span></p><p dir=3D"ltr" style=3D"line-heigh=
t:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font=
-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:=
baseline;white-space:pre-wrap"> =C2=A0try</span></p><p dir=3D"ltr" style=3D=
"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-siz=
e:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vert=
ical-align:baseline;white-space:pre-wrap"> =C2=A0{</span></p><p dir=3D"ltr"=
style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D=
"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transpa=
rent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0rcu_r=
eader an_rcu_reader;</span></p><p dir=3D"ltr" style=3D"line-height:1.38;mar=
gin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Ar=
ial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;w=
hite-space:pre-wrap"> =C2=A0=C2=A0=C2=A0my_rcu_type* my_rcu_object =3D =E2=
=80=A6; </span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;=
margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rg=
b(0,0,0);background-color:transparent;vertical-align:baseline;white-space:p=
re-wrap"> =C2=A0=C2=A0=C2=A0/*Suppose the thread gets preempted here. When =
rescheduled, it can continue running only as far as the next usage of *my_r=
cu_object inside do_something(), and will =E2=80=9Cthrow std::preemption_ex=
ception()=E2=80=9D before the object is accessed.*/</span></p><p dir=3D"ltr=
" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0do=
_something( my_rcu_object ); //Some use of protected objects, function will=
dereference it.</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-=
top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;=
color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white=
-space:pre-wrap"> =C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.3=
8;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-fami=
ly:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:basel=
ine;white-space:pre-wrap"> =C2=A0catch( std::preemption_exception const&=
; )</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margi=
n-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0=
,0);background-color:transparent;vertical-align:baseline;white-space:pre-wr=
ap"> =C2=A0{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;colo=
r:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spa=
ce:pre-wrap"> =C2=A0=C2=A0=C2=A0continue; //got preempted, restart section =
again</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0=
,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-=
wrap"> =C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-to=
p:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;co=
lor:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-s=
pace:pre-wrap"> =C2=A0catch(...)</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;fo=
nt-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-alig=
n:baseline;white-space:pre-wrap"> =C2=A0{</span></p><p dir=3D"ltr" style=3D=
"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-siz=
e:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vert=
ical-align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0throw;</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0p=
t"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);backgro=
und-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=
}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0=
);background-color:transparent;vertical-align:baseline;white-space:pre-wrap=
"> =C2=A0break; //successful, don=E2=80=99t run again.</span></p><p dir=3D"=
ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span styl=
e=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tra=
nsparent;vertical-align:baseline;white-space:pre-wrap">}</span></p><div><sp=
an style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-co=
lor:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span></=
div><div><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);b=
ackground-color:transparent;vertical-align:baseline;white-space:pre-wrap">S=
o, the programmer just needs to write the section code as a retryable trans=
action.</span></div><div><span style=3D"font-size:10pt;font-family:Arial;co=
lor:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-s=
pace:pre-wrap"><br></span></div></span></div></blockquote><div><br></div><d=
iv>=C2=A0<span style=3D"background-color: transparent; color: rgb(0, 0, 0);=
font-family: Arial; font-size: 10pt; white-space: pre-wrap;">Well, I guess=
breaking the protected section isn=E2=80=99t going to be feasible.</span><=
/div><span id=3D"docs-internal-guid-494eb903-7fff-a35b-e7f4-97e46b22ad3b"><=
br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0p=
t;"><span style=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0)=
; background-color: transparent; font-variant-numeric: normal; font-variant=
-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">How =
about then enabling the reclamation mechanism to first recognize which thre=
ads have been preempted inside a protected section, and then get a list of =
pointers to the specific protected objects that this preempted thread acces=
sed.</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;marg=
in-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: =
rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal; =
font-variant-east-asian: normal; vertical-align: baseline; white-space: pre=
-wrap;">Then it can add just these pointers to a separate protected list an=
d terminate the grace period.</span></p><br><p dir=3D"ltr" style=3D"line-he=
ight:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt=
; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;">I guess the thread will have to store =
all the protected types pointers that it accesses in a buffer (unique to ea=
ch thread). Then the reclamation mechanism will have to read it - I guess i=
t has to know that it strongly-happens-after the preempted thread has been =
preempted, or maybe send a SIGUSR1 to the thread.</span></p><br><p dir=3D"l=
tr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span styl=
e=3D"font-size: 10pt; font-family: Arial; color: rgb(0, 0, 0); background-c=
olor: transparent; font-variant-numeric: normal; font-variant-east-asian: n=
ormal; vertical-align: baseline; white-space: pre-wrap;">Is that possible?<=
/span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margi=
n-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; color: r=
gb(0, 0, 0); background-color: transparent; font-variant-numeric: normal; f=
ont-variant-east-asian: normal; vertical-align: baseline; white-space: pre-=
wrap;">itaj</span></p><div><span style=3D"font-size: 10pt; font-family: Ari=
al; color: rgb(0, 0, 0); background-color: transparent; font-variant-numeri=
c: normal; font-variant-east-asian: normal; vertical-align: baseline; white=
-space: pre-wrap;"><br></span></div></span></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9f6cb880-21cd-442c-a449-17f88c932db8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9f6cb880-21cd-442c-a449-17f88c932db8=
%40isocpp.org</a>.<br />
------=_Part_2839_1652106898.1542167592525--
------=_Part_2838_805128665.1542167592525--
.
Author: Itaj Sherman <itajsherman@gmail.com>
Date: Tue, 13 Nov 2018 20:51:49 -0800 (PST)
Raw View
------=_Part_933_755180508.1542171109564
Content-Type: multipart/alternative;
boundary="----=_Part_934_1015392843.1542171109565"
------=_Part_934_1015392843.1542171109565
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Wednesday, 14 November 2018 05:53:12 UTC+2, Itaj Sherman wrote:
>
>
>
> On Sunday, 11 November 2018 23:34:02 UTC+2, Itaj Sherman wrote:
>>
>> What happens if a user thread enters a section protected by a locked=20
>> rcu_reader instance, and gets preempted by the scheduler inside the=20
>> section?!
>>
>> When it wakes up, it supposedly continues to run inside the section.
>>
>> Which means that all rcu protected objects used inside the section have=
=20
>> to be delayed for a long time until after the thread gets scheduled agai=
n.
>>
>> I want to propose the following suggestion. I really am not sure if it=
=E2=80=99s=20
>> feasible, it needs compiler and OS support that I=E2=80=99m not sure is =
always=20
>> available.
>>
>> A tag or some keyword, let=E2=80=99s say PREEMPTION_BREAK that can mark =
the=20
>> enclosed {} section of the protected code:
>>
>> NON_PREEMPTABLE
>>
>> {
>>
>> rcu_reader an_rcu_reader;
>>
>> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>>
>> do_something( *my_rcu_object ); //Some use of protected objects=20
>>
>> }
>>
>> The compiler with OS supports needs to make sure of the following:
>>
>>
>> 1. If the execution gets preempted within the section, it is as-if it=20
>> calls an_rcu_reader.unlock() just before the thread got preempted. So th=
at=20
>> the thread is not considered inside an rcu protected section anymore,=20
>> during the time it won=E2=80=99t be running. And object it protected can=
be=20
>> reclaimed.
>>
>>
>> 2.When the thread gets scheduled again, it will restart running from the=
=20
>> beginning of the section NON_PREEMPTABLE (after stack unwinding), as if =
an=20
>> exception was thrown and caught at the section level, and then the secti=
on=20
>> restarts running (see code below). It doesn=E2=80=99t have to throw imme=
diately at=20
>> the preemption position, it can continue running as far as the next time=
an=20
>> instance of an rcu protected type is used, and throw the exception at th=
e=20
>> next usage.
>>
>> Basically the compiler has to add code whenever an instance of an rcu=20
>> protected type is used, to check if within a NON_PREEMPTABLE section, an=
d=20
>> the thread actually has been preempted after the section started, then=
=20
>> as-if throw an exception.
>>
>>
>> while(true)
>>
>> {
>>
>> try
>>
>> {
>>
>> rcu_reader an_rcu_reader;
>>
>> my_rcu_type* my_rcu_object =3D =E2=80=A6;=20
>>
>> /*Suppose the thread gets preempted here. When rescheduled, it can=20
>> continue running only as far as the next usage of *my_rcu_object inside=
=20
>> do_something(), and will =E2=80=9Cthrow std::preemption_exception()=E2=
=80=9D before the=20
>> object is accessed.*/
>>
>> do_something( my_rcu_object ); //Some use of protected objects,=20
>> function will dereference it.
>>
>> }
>>
>> catch( std::preemption_exception const& )
>>
>> {
>>
>> continue; //got preempted, restart section again
>>
>> }
>>
>> catch(...)
>>
>> {
>>
>> throw;
>>
>> }
>>
>> break; //successful, don=E2=80=99t run again.
>>
>> }
>>
>> So, the programmer just needs to write the section code as a retryable=
=20
>> transaction.
>>
>>
> Well, I guess breaking the protected section isn=E2=80=99t going to be f=
easible.
>
> How about then enabling the reclamation mechanism to first recognize whic=
h=20
> threads have been preempted inside a protected section, and then get a li=
st=20
> of pointers to the specific protected objects that this preempted thread=
=20
> accessed.
>
> Then it can add just these pointers to a separate protected list and=20
> terminate the grace period.
>
> I guess the thread will have to store all the protected types pointers=20
> that it accesses in a buffer (unique to each thread). Then the reclamatio=
n=20
> mechanism will have to read it - I guess it has to know that it=20
> strongly-happens-after the preempted thread has been preempted, or maybe=
=20
> send a SIGUSR1 to the thread.
>
> Is that possible?
>
> itaj
>
>
If it could be done inside a SIGUSR1, then the list doesn't need to contain=
=20
all addresses that were read. It only needs addresses that the thread=20
already had gotten, and might access after it is rescheduled - which means=
=20
they are all accessible through variables on the thread's stack.
Then it wouldn't need a separate buffer. It's just have to be so that all=
=20
these addresses are kept in special pointer objects, instead of raw=20
pointers. Then it could be some generalized linked list that resides inside=
=20
the thread=E2=80=99s stack.
For local variable pointers, instead of T* use protected_ptr<T> (code=20
below).
It=E2=80=99s somewhat like the hazard pointer usage, but they=E2=80=99re st=
ored only on the=20
stack with non-atomic operations.
If the thread collects addresses in some containers then more specialized=
=20
classes have to be defined. E.g. For some_container<T*> there would have to=
=20
be a compatible some_container_of_protected_ptr<T>. And ultimately the list=
=20
could be read by calling a thread_local function object.
struct protected_address_node
{
void const* p_; //or some other type erasure
protected_address_node* next_;
};
thread_local protected_address_node* protected_list_head_ =3D nullptr;
template< typename T >
class protected_ptr
{
private:
T* p_;
protected_address_node node_;
public:
protected_ptr( T* p )
:
p_(p),
node_{ static_cast<...>(p), protected_list_head_ }
{
protected_list_head_ =3D &node_;
}
~protected_ptr()
{
protected_list_head_ =3D node_.next_;
}
T* get() const { return p_; }
};
itaj
=20
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/249e7fc7-1a72-49dc-9d9f-7fef26143155%40isocpp.or=
g.
------=_Part_934_1015392843.1542171109565
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, 14 November 2018 05:53:12 UTC+2, Ita=
j Sherman wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><br><br>On Sunday, 11 November 2018 23:34:02 UTC+2, Itaj Sherman wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bord=
er-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><span><p dir=3D"l=
tr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap">What happens if a use=
r thread enters a section protected by a locked rcu_reader instance, and ge=
ts preempted by the scheduler inside the section?!</span></p><p dir=3D"ltr"=
style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D=
"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transpa=
rent;vertical-align:baseline;white-space:pre-wrap">When it wakes up, it sup=
posedly continues to run inside the section.</span></p><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;v=
ertical-align:baseline;white-space:pre-wrap">Which means that all rcu prote=
cted objects used inside the section have to be delayed for a long time unt=
il after the thread gets scheduled again.</span></p><br><p dir=3D"ltr" styl=
e=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font=
-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;=
vertical-align:baseline;white-space:pre-wrap">I want to propose the followi=
ng suggestion. I really am not sure if it=E2=80=99s feasible, it needs comp=
iler and OS support that I=E2=80=99m not sure is always available.</span></=
p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);back=
ground-color:transparent;vertical-align:baseline;white-space:pre-wrap">A ta=
g or some keyword, let=E2=80=99s say PREEMPTION_BREAK that can mark the enc=
losed {} section of the protected code:</span></p><br><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;v=
ertical-align:baseline;white-space:pre-wrap">NON_PREEMPTABLE</span></p><p d=
ir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><spa=
n style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-col=
or:transparent;vertical-align:baseline;white-space:pre-wrap">{</span></p><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0rcu_r=
eader an_rcu_reader;</span></p><p dir=3D"ltr" style=3D"line-height:1.38;mar=
gin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Ar=
ial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;w=
hite-space:pre-wrap"> =C2=A0my_rcu_type* my_rcu_object =3D =E2=80=A6; </spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);back=
ground-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=
=A0do_something( *my_rcu_object ); //Some use of protected objects </span><=
/p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0p=
t"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);backgro=
und-color:transparent;vertical-align:baseline;white-space:pre-wrap">}</span=
></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bot=
tom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);b=
ackground-color:transparent;vertical-align:baseline;white-space:pre-wrap">T=
he compiler with OS supports needs to make sure of the following:</span></p=
><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"background-color:transparent;font-size:10pt;white-space:pre=
-wrap;color:rgb(0,0,0);font-family:Arial"><br></span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"bac=
kground-color:transparent;font-size:10pt;white-space:pre-wrap;color:rgb(0,0=
,0);font-family:Arial">1. If the execution gets preempted within the sectio=
n, it is as-if it calls an_rcu_reader.unlock() just before the thread got p=
reempted. So that the thread is not considered inside an rcu protected sect=
ion anymore, during the time it won=E2=80=99t be running. And object it pro=
tected can be reclaimed.</span></p><p dir=3D"ltr" style=3D"line-height:1.38=
;margin-top:0pt;margin-bottom:0pt"><span style=3D"background-color:transpar=
ent;font-size:10pt;white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial"=
><br></span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"background-color:transparent;font-size:10pt;=
white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial">2.When the thread =
gets scheduled again, it will restart running from the beginning of the sec=
tion NON_PREEMPTABLE (after stack unwinding), as if an exception was thrown=
and caught at the section level, and then the section restarts running (se=
e code below). It doesn=E2=80=99t have to throw immediately at the preempti=
on position, it can continue running as far as the next time an instance of=
an rcu protected type is used, and throw the exception at the next usage.<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"background-color:transparent;font-size:10pt;white-=
space:pre-wrap;color:rgb(0,0,0);font-family:Arial">Basically the compiler h=
as to add code whenever an instance of an rcu protected type is used, to ch=
eck if within a NON_PREEMPTABLE section, and the thread actually has been p=
reempted after the section started, then as-if throw an exception.</span></=
p><br><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);=
background-color:transparent;vertical-align:baseline;white-space:pre-wrap">=
while(true)</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color=
:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spac=
e:pre-wrap">{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top=
:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;col=
or:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-sp=
ace:pre-wrap"> =C2=A0try</span></p><p dir=3D"ltr" style=3D"line-height:1.38=
;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-famil=
y:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseli=
ne;white-space:pre-wrap"> =C2=A0{</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;f=
ont-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-ali=
gn:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0rcu_reader an_rcu_read=
er;</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margi=
n-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0=
,0);background-color:transparent;vertical-align:baseline;white-space:pre-wr=
ap"> =C2=A0=C2=A0=C2=A0my_rcu_type* my_rcu_object =3D =E2=80=A6; </span></p=
><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);backgroun=
d-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0=
=C2=A0=C2=A0/*Suppose the thread gets preempted here. When rescheduled, it =
can continue running only as far as the next usage of *my_rcu_object inside=
do_something(), and will =E2=80=9Cthrow std::preemption_exception()=E2=80=
=9D before the object is accessed.*/</span></p><p dir=3D"ltr" style=3D"line=
-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10p=
t;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-=
align:baseline;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0do_something( my_rc=
u_object ); //Some use of protected objects, function will dereference it.<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);=
background-color:transparent;vertical-align:baseline;white-space:pre-wrap">=
=C2=A0}</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;=
margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rg=
b(0,0,0);background-color:transparent;vertical-align:baseline;white-space:p=
re-wrap"> =C2=A0catch( std::preemption_exception const& )</span></p><p =
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><sp=
an style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-co=
lor:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0{</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);back=
ground-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=
=A0=C2=A0=C2=A0continue; //got preempted, restart section again</span></p><=
p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-=
color:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0}</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bott=
om:0pt"><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);ba=
ckground-color:transparent;vertical-align:baseline;white-space:pre-wrap"> =
=C2=A0catch(...)</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-=
top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;=
color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white=
-space:pre-wrap"> =C2=A0{</span></p><p dir=3D"ltr" style=3D"line-height:1.3=
8;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-fami=
ly:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:basel=
ine;white-space:pre-wrap"> =C2=A0=C2=A0=C2=A0throw;</span></p><p dir=3D"ltr=
" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0}</span></p><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap"> =C2=A0break=
; //successful, don=E2=80=99t run again.</span></p><p dir=3D"ltr" style=3D"=
line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size=
:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;verti=
cal-align:baseline;white-space:pre-wrap">}</span></p><div><span style=3D"fo=
nt-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:transparen=
t;vertical-align:baseline;white-space:pre-wrap"><br></span></div><div><span=
style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-colo=
r:transparent;vertical-align:baseline;white-space:pre-wrap">So, the program=
mer just needs to write the section code as a retryable transaction.</span>=
</div><div><span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0)=
;background-color:transparent;vertical-align:baseline;white-space:pre-wrap"=
><br></span></div></span></div></blockquote><div><br></div><div>=C2=A0<span=
style=3D"background-color:transparent;color:rgb(0,0,0);font-family:Arial;f=
ont-size:10pt;white-space:pre-wrap">Well, I guess breaking the protected se=
ction isn=E2=80=99t going to be feasible.</span></div><span><br><p dir=3D"l=
tr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap">How about then enabli=
ng the reclamation mechanism to first recognize which threads have been pre=
empted inside a protected section, and then get a list of pointers to the s=
pecific protected objects that this preempted thread accessed.</span></p><p=
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap">Then it can =
add just these pointers to a separate protected list and terminate the grac=
e period.</span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top=
:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font-family:Arial;col=
or:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-sp=
ace:pre-wrap">I guess the thread will have to store all the protected types=
pointers that it accesses in a buffer (unique to each thread). Then the re=
clamation mechanism will have to read it - I guess it has to know that it s=
trongly-happens-after the preempted thread has been preempted, or maybe sen=
d a SIGUSR1 to the thread.</span></p><br><p dir=3D"ltr" style=3D"line-heigh=
t:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:10pt;font=
-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:=
baseline;white-space:pre-wrap">Is that possible?</span></p><br><p dir=3D"lt=
r" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap">itaj</span></p><div><=
span style=3D"font-size:10pt;font-family:Arial;color:rgb(0,0,0);background-=
color:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span>=
</div></span></div></blockquote><div><br></div><div><span id=3D"docs-intern=
al-guid-9af5d8a0-7fff-f4ae-50e2-754f6e9e2bdf"><p dir=3D"ltr" style=3D"line-=
height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10=
pt; font-family: Arial; font-variant-numeric: normal; font-variant-east-asi=
an: normal; vertical-align: baseline; white-space: pre-wrap;">If it could b=
e done inside a SIGUSR1, then the list doesn't need to contain all addr=
esses that were read. It only needs addresses that the thread already had g=
otten, and might access after it is rescheduled - which means they are all =
accessible through variables on the thread's stack.</span></p><p dir=3D=
"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span st=
yle=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: normal; f=
ont-variant-east-asian: normal; vertical-align: baseline; white-space: pre-=
wrap;">Then it wouldn't need a separate buffer. It's just have to b=
e so that all these addresses are kept in special pointer objects, instead =
of raw pointers. Then it could be some generalized linked list that resides=
inside the thread=E2=80=99s stack.</span><span style=3D"font-size: 10pt; f=
ont-family: Arial; font-variant-numeric: normal; font-variant-east-asian: n=
ormal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-l=
ine-break"></span><span style=3D"font-size: 10pt; font-family: Arial; font-=
variant-numeric: normal; font-variant-east-asian: normal; vertical-align: b=
aseline; white-space: pre-wrap;">For local variable pointers, instead of T*=
use protected_ptr<T> (code below).</span></p><p dir=3D"ltr" style=3D=
"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-si=
ze: 10pt; font-family: Arial; font-variant-numeric: normal; font-variant-ea=
st-asian: normal; vertical-align: baseline; white-space: pre-wrap;">It=E2=
=80=99s somewhat like the hazard pointer usage, but they=E2=80=99re stored =
only on the stack with non-atomic operations.</span><span style=3D"font-siz=
e: 10pt; font-family: Arial; font-variant-numeric: normal; font-variant-eas=
t-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br clas=
s=3D"kix-line-break"></span><span style=3D"font-size: 10pt; font-family: Ar=
ial; font-variant-numeric: normal; font-variant-east-asian: normal; vertica=
l-align: baseline; white-space: pre-wrap;">If the thread collects addresses=
in some containers then more specialized classes have to be defined. E.g. =
For some_container<T*> there would have to be a compatible some_conta=
iner_of_protected_ptr<T>. And ultimately the list could be read by ca=
lling a thread_local function object.</span></p><br><p dir=3D"ltr" style=3D=
"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-si=
ze: 10pt; font-family: Arial; font-variant-numeric: normal; font-variant-ea=
st-asian: normal; vertical-align: baseline; white-space: pre-wrap;">struct =
protected_address_node</span></p><p dir=3D"ltr" style=3D"line-height:1.38;m=
argin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-fami=
ly: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; v=
ertical-align: baseline; white-space: pre-wrap;">{</span></p><p dir=3D"ltr"=
style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;"><span class=3D"Apple-tab-span" style=3D"white-space:pre;"> </span></spa=
n><span style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric:=
normal; font-variant-east-asian: normal; vertical-align: baseline; white-s=
pace: pre-wrap;">void const* p_; //or some other type erasure</span></p><p =
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><s=
pan style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: nor=
mal; font-variant-east-asian: normal; vertical-align: baseline; white-space=
: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space:pre;"> </s=
pan></span><span style=3D"font-size: 10pt; font-family: Arial; font-variant=
-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline=
; white-space: pre-wrap;">protected_address_node* next_;</span></p><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span=
style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: normal=
; font-variant-east-asian: normal; vertical-align: baseline; white-space: p=
re-wrap;">};</span></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-=
top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Ar=
ial; font-variant-numeric: normal; font-variant-east-asian: normal; vertica=
l-align: baseline; white-space: pre-wrap;">thread_local protected_address_n=
ode* protected_list_head_ =3D nullptr;</span></p><br><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size: 10pt; font-family: Arial; font-variant-numeric: normal; font-variant=
-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">temp=
late< typename T ></span></p><p dir=3D"ltr" style=3D"line-height:1.38=
;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-fa=
mily: Arial; font-variant-numeric: normal; font-variant-east-asian: normal;=
vertical-align: baseline; white-space: pre-wrap;">class protected_ptr</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom=
:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; font-variant-num=
eric: normal; font-variant-east-asian: normal; vertical-align: baseline; wh=
ite-space: pre-wrap;">{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;=
margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-fam=
ily: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; =
vertical-align: baseline; white-space: pre-wrap;">private:</span></p><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span=
style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: normal=
; font-variant-east-asian: normal; vertical-align: baseline; white-space: p=
re-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space:pre;"> </span=
></span><span style=3D"font-size: 10pt; font-family: Arial; font-variant-nu=
meric: normal; font-variant-east-asian: normal; vertical-align: baseline; w=
hite-space: pre-wrap;">T* p_;</span></p><p dir=3D"ltr" style=3D"line-height=
:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; fo=
nt-family: Arial; font-variant-numeric: normal; font-variant-east-asian: no=
rmal; vertical-align: baseline; white-space: pre-wrap;"><span class=3D"Appl=
e-tab-span" style=3D"white-space:pre;"> </span></span><span style=3D"font-s=
ize: 10pt; font-family: Arial; font-variant-numeric: normal; font-variant-e=
ast-asian: normal; vertical-align: baseline; white-space: pre-wrap;">protec=
ted_address_node node_;</span></p><br><p dir=3D"ltr" style=3D"line-height:1=
..38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font=
-family: Arial; font-variant-numeric: normal; font-variant-east-asian: norm=
al; vertical-align: baseline; white-space: pre-wrap;">public:</span></p><p =
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><s=
pan style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: nor=
mal; font-variant-east-asian: normal; vertical-align: baseline; white-space=
: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space:pre;"> </s=
pan></span><span style=3D"font-size: 10pt; font-family: Arial; font-variant=
-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline=
; white-space: pre-wrap;">protected_ptr( T* p )</span></p><p dir=3D"ltr" st=
yle=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"f=
ont-size: 10pt; font-family: Arial; font-variant-numeric: normal; font-vari=
ant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><=
span class=3D"Apple-tab-span" style=3D"white-space:pre;"> </span></span><sp=
an style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: norm=
al; font-variant-east-asian: normal; vertical-align: baseline; white-space:=
pre-wrap;">:</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top=
:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial=
; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-a=
lign: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-span" styl=
e=3D"white-space:pre;"> </span></span><span style=3D"font-size: 10pt; font-=
family: Arial; font-variant-numeric: normal; font-variant-east-asian: norma=
l; vertical-align: baseline; white-space: pre-wrap;"><span class=3D"Apple-t=
ab-span" style=3D"white-space:pre;"> </span></span><span style=3D"font-size=
: 10pt; font-family: Arial; font-variant-numeric: normal; font-variant-east=
-asian: normal; vertical-align: baseline; white-space: pre-wrap;">p_(p),</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bott=
om:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; font-variant-n=
umeric: normal; font-variant-east-asian: normal; vertical-align: baseline; =
white-space: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space=
:pre;"> </span></span><span style=3D"font-size: 10pt; font-family: Arial; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-span" style=
=3D"white-space:pre;"> </span></span><span style=3D"font-size: 10pt; font-f=
amily: Arial; font-variant-numeric: normal; font-variant-east-asian: normal=
; vertical-align: baseline; white-space: pre-wrap;">node_{ static_cast<.=
...>(p), protected_list_head_ }</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt=
; font-family: Arial; font-variant-numeric: normal; font-variant-east-asian=
: normal; vertical-align: baseline; white-space: pre-wrap;"><span class=3D"=
Apple-tab-span" style=3D"white-space:pre;"> </span></span><span style=3D"fo=
nt-size: 10pt; font-family: Arial; font-variant-numeric: normal; font-varia=
nt-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">{<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bo=
ttom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; font-variant=
-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline=
; white-space: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-spa=
ce:pre;"> </span></span><span style=3D"font-size: 10pt; font-family: Arial;=
font-variant-numeric: normal; font-variant-east-asian: normal; vertical-al=
ign: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-span" style=
=3D"white-space:pre;"> </span></span><span style=3D"font-size: 10pt; font-f=
amily: Arial; font-variant-numeric: normal; font-variant-east-asian: normal=
; vertical-align: baseline; white-space: pre-wrap;">protected_list_head_ =
=3D &node_;</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-t=
op:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Ari=
al; font-variant-numeric: normal; font-variant-east-asian: normal; vertical=
-align: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-span" st=
yle=3D"white-space:pre;"> </span></span><span style=3D"font-size: 10pt; fon=
t-family: Arial; font-variant-numeric: normal; font-variant-east-asian: nor=
mal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><br><p d=
ir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><sp=
an style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: norm=
al; font-variant-east-asian: normal; vertical-align: baseline; white-space:=
pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space:pre;"> </sp=
an></span><span style=3D"font-size: 10pt; font-family: Arial; font-variant-=
numeric: normal; font-variant-east-asian: normal; vertical-align: baseline;=
white-space: pre-wrap;">~protected_ptr()</span></p><p dir=3D"ltr" style=3D=
"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-si=
ze: 10pt; font-family: Arial; font-variant-numeric: normal; font-variant-ea=
st-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><span c=
lass=3D"Apple-tab-span" style=3D"white-space:pre;"> </span></span><span sty=
le=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: normal; fo=
nt-variant-east-asian: normal; vertical-align: baseline; white-space: pre-w=
rap;">{</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;m=
argin-bottom:0pt;"><span style=3D"font-size: 10pt; font-family: Arial; font=
-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: =
baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre;"> </span></span><span style=3D"font-size: 10pt; font-family=
: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; ver=
tical-align: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-spa=
n" style=3D"white-space:pre;"> </span></span><span style=3D"font-size: 10pt=
; font-family: Arial; font-variant-numeric: normal; font-variant-east-asian=
: normal; vertical-align: baseline; white-space: pre-wrap;">protected_list_=
head_ =3D node_.next_;</span></p><p dir=3D"ltr" style=3D"line-height:1.38;m=
argin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: 10pt; font-fami=
ly: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; v=
ertical-align: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-s=
pan" style=3D"white-space:pre;"> </span></span><span style=3D"font-size: 10=
pt; font-family: Arial; font-variant-numeric: normal; font-variant-east-asi=
an: normal; vertical-align: baseline; white-space: pre-wrap;">}</span></p><=
br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0p=
t;"><span style=3D"font-size: 10pt; font-family: Arial; font-variant-numeri=
c: normal; font-variant-east-asian: normal; vertical-align: baseline; white=
-space: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space:pre;=
"> </span></span><span style=3D"font-size: 10pt; font-family: Arial; font-v=
ariant-numeric: normal; font-variant-east-asian: normal; vertical-align: ba=
seline; white-space: pre-wrap;">T* get() const { return p_; }</span></p><p =
dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><s=
pan style=3D"font-size: 10pt; font-family: Arial; font-variant-numeric: nor=
mal; font-variant-east-asian: normal; vertical-align: baseline; white-space=
: pre-wrap;">};</span></p><br></span>itaj<br><br>=C2=A0</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/249e7fc7-1a72-49dc-9d9f-7fef26143155%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/249e7fc7-1a72-49dc-9d9f-7fef26143155=
%40isocpp.org</a>.<br />
------=_Part_934_1015392843.1542171109565--
------=_Part_933_755180508.1542171109564--
.