problem mutex-thread "Unlocking mutex owned by another thread ???"

Discussion in 'C++' started by NaeiKinDus, Apr 14, 2007.

  1. NaeiKinDus

    NaeiKinDus Guest

    Hello, i'm trying to program a thread that would be locked (by a
    mutex) and that would only be unlocked once that a function is done.
    The purpose is to generate data, and unlock the mutex in order to
    activate the thread once the data is generated.

    step 1: initialize the mutex

    mx (the mutex is part of the class "cl")

    class Client
    {
    ...

    public:
    pthread_mutex_t mx;

    ...
    }

    pthread_mutex_init(&cl->mx, NULL);

    step 2:

    as i'm calling a thread, i have to pass in param a structure :

    struct S_PARAMS
    {
    ...

    pthread_mutex_t *mx;

    ...
    } typedef T_PARAMS;

    i create the thread and i copy the mutex in the param structure :

    pthread_t thread;
    params->mx = &cl->mx;

    if ((thId = pthread_create(&thread, NULL, OBody::thFileSender, (void
    *)params)) != 0)
    {
    THREAD NOT CREATED ... throw ...
    }
    else
    {

    }
    NaeiKinDus, Apr 14, 2007
    #1
    1. Advertising

  2. NaeiKinDus

    Jack Klein Guest

    On 14 Apr 2007 09:51:20 -0700, "NaeiKinDus" <>
    wrote in comp.lang.c++:

    > Hello, i'm trying to program a thread that would be locked (by a
    > mutex) and that would only be unlocked once that a function is done.
    > The purpose is to generate data, and unlock the mutex in order to
    > activate the thread once the data is generated.


    This group discusses the standard C++ language, which does not define
    either threads or mutexes.

    [snip]


    > pthread_mutex_t mx;


    pthreads are a system-specific extension and off-topic here.

    You need to ask this question in a newsgroup that supports your
    particular operating system. Or perhaps
    news:comp.programming.threads. Not in a language group.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Apr 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,493
  2. NaeiKinDus
    Replies:
    3
    Views:
    605
    James Kanze
    Apr 15, 2007
  3. Roy Smith

    Mutex not thread safe? PEP-3108.

    Roy Smith, Sep 23, 2008, in forum: Python
    Replies:
    1
    Views:
    286
  4. sven
    Replies:
    2
    Views:
    1,933
    Roy Smith
    Dec 4, 2009
  5. Guest
    Replies:
    10
    Views:
    247
    Robert Klemme
    Dec 27, 2005
Loading...

Share This Page