Itaj Sherman
2018-11-11 21:34:02 UTC
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?!
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
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âs
feasible, it needs compiler and OS support that Iâm not sure is always
available.
A tag or some keyword, letâs say PREEMPTION_BREAK that can mark the
enclosed {} section of the protected code:
NON_PREEMPTABLE
{
rcu_reader an_rcu_reader;
my_rcu_type* my_rcu_object = âŠ;
do_something( *my_rcu_object ); //Some use of protected objects
}
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
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ât be running. And object it protected can be reclaimed.
2.When the thread gets scheduled again, it will restart running from the
beginning of the section NON_PREEMPTABLE (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ât have to throw immediately at
the preemption 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.
Basically the compiler has to add code whenever an instance of an rcu
protected type is used, to check if within a NON_PREEMPTABLE section, and
the thread actually has been preempted after the section started, then
as-if throw an exception.
while(true)
{
try
{
rcu_reader an_rcu_reader;
my_rcu_type* my_rcu_object = âŠ;
/*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 âthrow std::preemption_exception()â before the
object is accessed.*/
do_something( my_rcu_object ); //Some use of protected objects, function
will dereference it.
}
catch( std::preemption_exception const& )
{
continue; //got preempted, restart section again
}
catch(...)
{
throw;
}
break; //successful, donât run again.
}
So, the programmer just needs to write the section code as a retryable
transaction.
rcu_reader instance, and gets preempted by the scheduler inside the
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
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âs
feasible, it needs compiler and OS support that Iâm not sure is always
available.
A tag or some keyword, letâs say PREEMPTION_BREAK that can mark the
enclosed {} section of the protected code:
NON_PREEMPTABLE
{
rcu_reader an_rcu_reader;
my_rcu_type* my_rcu_object = âŠ;
do_something( *my_rcu_object ); //Some use of protected objects
}
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
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ât be running. And object it protected can be reclaimed.
2.When the thread gets scheduled again, it will restart running from the
beginning of the section NON_PREEMPTABLE (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ât have to throw immediately at
the preemption 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.
Basically the compiler has to add code whenever an instance of an rcu
protected type is used, to check if within a NON_PREEMPTABLE section, and
the thread actually has been preempted after the section started, then
as-if throw an exception.
while(true)
{
try
{
rcu_reader an_rcu_reader;
my_rcu_type* my_rcu_object = âŠ;
/*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 âthrow std::preemption_exception()â before the
object is accessed.*/
do_something( my_rcu_object ); //Some use of protected objects, function
will dereference it.
}
catch( std::preemption_exception const& )
{
continue; //got preempted, restart section again
}
catch(...)
{
throw;
}
break; //successful, donât run again.
}
So, the programmer just needs to write the section code as a retryable
transaction.
--
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 email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@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.org.
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 email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@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.org.