>> 3. Does transitivity work? i.e. if therer's a thread 3 that's also loading
>> from p, and if thread 2 faults on the load while thread 3 doesn't, can we
>> say that thread 2 faults after the mprotect on thread 1 which is after the
>> load on thread 3 and therefore the load (and fault) on thread 2 happens
>> after the load on thread 3?
>
>
> Same as (2) above. You'd need to describe how threads 1 and 2 observe
> whether or not thread 3's load has happened, and whether or not it has
> faulted. Then, depending on how that information is communicated, you would
> be able to establish some ordering.
The "safe assumption" 2 above also made it more clear to me why I feel
like this might not be true even if both of the previous ones might be
true. I'm now imagining a naive implementation of mprotect where the
access bit is sequentially flipped on all the threads from the thread
issuing mprotect, i.e. mprotect(p, PROT_NONE) is really
```
for (thread: all_threads) {
mprotect_on_thread(thread, p, PROT_NONE)
}
```
In that case for three threads executing (starting `*ga == 0`)
```
// thread 1
mprotect(p, PROT_NONE)
// thread 2
*(volatile int*)p;
a = *ga; // in signal handler
// thread 3
*ga = 1;
*(volatile int*)p;
```
A possible "sequential consistent" execution could be
```
mprotect_on_thread(1, p, PROT_NONE) // Thread 1
mprotect_on_thread(2, p, PROT_NONE) // Thread 1
*(volatile int*)p; // Thread 2, this faults.
a = *ga; // in signal handler // Thread 2
*ga = 1; // Thread 3
*(volatile int*)p; // Thread 3, this doesn't fault.
mprotect_on_thread(3, p, PROT_NONE) // Thread 1
```
After all three threads finishes execution we'll have `a == 0`. Even
though the `a = *ga` appears to be executed after `mprotect` (though
not after `mprotect` returns) and `*ga = 1` appears to be executed
before `mprotect`.
Note that this naive model won't break 1 or 2 (both thread 2 and 3
will still be synchronized to thread 1 since thread 1 cannot do
anything before mprotect returns). Can this actually happen? (I'll
probably test this myself later though I've never tested anything like
this that involves more than two threads yet....)
--
You received this message because you are subscribed to the Google Groups
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.