2009/5/14 Jim Nelson <[email protected]>: > I noticed while coding with threads that the statement lock (this) is not > available. valac returns this error: > > error: Expression is either not a member access or does not denote a > lockable member > > Is it part of the language spec that only members can be locked and not the > "this" object itself? I can't find documentation either way. > > I've also discovered you cannot lock an object externally, a la: > > Obj o = new Obj(); > lock (o) { > o.get_value(); > } > > does not compile, with the same error. Again, I'm unsure if this is part of > the spec. > > Since I'm on the subject, if you are able to lock (this), it would be nice > if you could lock an object throughout a method's execution, a la Java's > synchronized methods: > > public lock void atomic_op() { > } > > -- Jim
Yeah, the syntactic locking stuff is a little hard to put to good use at the moment. What does work well is using GLib's Mutex and Cond classes directly. That gives you as many separate locks as you can want. It is more work than it could be though, and you have to make sure you don't try to claim a mutex twice with the same thread which Java saves you from. There are some samples at http://live.gnome.org/Vala/ThreadingSamples, although the first doesn't look to quite work, as it tries to join on two threads, but that is an unrelated issue. -- Phil Housley _______________________________________________ Vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
