DragonFly BSD
DragonFly kernel List (threaded) for 2005-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Threading, mutexes, tokens...


From: Ivan Voras <ivoras@xxxxxx>
Date: Thu, 03 Feb 2005 12:37:24 +0100

This is a "I'd like to learn it, finally" post :)

So far, I've been coding userland applications (C, Java, scripting languages...), where I use mutexes to serialize access to variables, structures, etc. A (simple) example:

struct {
   mutex_t lock;
   int a;
   int b;
} my_struct;

void thread_proc() {
   while (something) {
      lock_mutex(data.lock);
      modify(&data.a);
      release_mutex(data.lock);
      do_stuff();
   }
}

void main() {
   thread_t t1 = make_thread(thread_proc); // create&start
   thread_t t2 = make_thread(thread_proc);

   sleep(1000); // or do something usefull
}

I see this is fairly different (trivially simple?) than situations reffered to in various posts explaining mutexes and tokens - specifically, I don't "see" the need for "With a hard mutex model you have to pass your mutex down into other subsystems that you call so they can release it before they potentially block, or you have to temporarily release your mutex yourself, or a myrid of other issues" (quote from Matt's recent interview). I'm not experienced enough, so could someone give me a pseudocode-example of this (prefferably in a real-world case?)?

How (and if?) would my example, and the complex one, be changed by using "tokens"? (prefferably, could someone show me using a similar pseudocode?) Do Dragonfly tokens have any effect on userspace applications?

Thanks!



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]