Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"05-25-10 - Thread Insurance"

5 Comments -

1 – 5 of 5
Blogger Kevin Gadd said...

The exception handler approach would work, but the exceptions would end up being really expensive. Maybe you could use that approach to run automated tests of your app to verify the thread-safety, but leave the exceptions off in actual builds when you use them to crunch on lots of data?

May 25, 2010 at 8:27 PM

Blogger Tom Forsyth said...

> This is just my hate for having rules for code correctness that are not enforced by the compiler or at least by run-time asserts.

Isn't that what "const" is for?

Thankyou folks, I'm here all night.

May 26, 2010 at 1:05 AM

Blogger Brian said...

Catching page faults I believe is pretty expensive if you actually take the page faults often. You can typically set up stuff like this on a per process basis in Linux. You would map shared pages to let each process see the others. I'd imagine that windows would also support this type of thing.

We're actually playing around with language support for stuff like this and having the type checker in the compiler complain about accessing protected data. It appears to be pretty useful. If we get some time, we might port it to annotations in Java so people can actually use it.

May 26, 2010 at 1:39 AM

Blogger cbloom said...

"Catching page faults I believe is pretty expensive if you actually take the page faults often."

Yeah, it would be a debug-runs only thing, but I wonder if it would be too slow even for debug testing runs.

"You can typically set up stuff like this on a per process basis in Linux. You would map shared pages to let each process see the others. I'd imagine that windows would also support this type of thing."

You can do it per-process in Windows, but I think that's just too much friction. If you use processes rather than threads it is much easier to enforce cleanness because there is no implicitly shared memory, all sharing must be done explicitly by mapping process memory to each other.

"We're actually playing around with language support for stuff like this and having the type checker in the compiler complain about accessing protected data."

Yeah there is a lot of good work in this direction (see Bartosz etc and previous posts on my blog), but it really only applies well to the struct-critsec kind of paradigm, not to the kind of ad-hoc threading I'm talking about here.

May 26, 2010 at 11:25 AM

Blogger Thatcher Ulrich said...

You could implement this with a handle or smart ptr idiom, with methods to grab a mutable or const ptr to the actual data, and those methods assert that the current thread has the right permissions. You still have a code-correctness criterion which is "don't pass bare pointers between threads."

May 26, 2010 at 6:07 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.