Results 1 to 4 of 4

Thread: question about CL_Mutex

  1. #1

    Default question about CL_Mutex

    I want to know that is mutex avalable wherever it can be called?
    even between an addon thread and the main thread?

    I don't know how to make a quick test code to confirm it myself

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    I'm sorry, but I have no idea what you are asking about.

  3. #3

    Default

    for example
    class class_monkey
    {
    CL_Mutex* lpmu;
    class_monkey(CL_Mutex* mu){lpmu = mu};
    eat_banana()
    {
    lpmu->lock();
    //do sth
    lpmu->unlock();
    }
    }
    class class_baboon
    {
    CL_Mutex* lpmu;
    class_baboon(CL_Mutex* mu){lpmu = mu};
    eat_banana()
    {
    lpmu->lock();
    //do sth
    lpmu->unlock();
    }
    }
    main()
    {
    CL_Mutex mu1;
    class_monkey monkey1(&mu1); //pass the mutex pointer to any class
    class_baboom baboon1(&mu1);
    CL_Thread thread1, thread2;
    thread1.start(monkey1, &class_monkey::eat_banana);
    thread2.start(baboon1, &class_baboon::eat_banana);
    thread1.join();
    thread2.join();
    monkey1.eat_banana();
    baboon1.eat_banana();
    }

    so will all of them eat_banana safe?

    sorry I'm not good at English..

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Yes, they will eat banana safely

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •