www.digitalmars.com         C & C++   DMDScript  

D - More than one out parameter a problem

Is this phenomenon known?

Having one or the other of the parameters to XFactory::X_Acquire() as an out
parameter works fine, but if both are we get an crash. I have not boiled
this right down, but it could be done so by changing worker_proc into main.

class X
{
}

class XFactory
{
private:
    static this()
    {
      sm_semaphore = new Semaphore(NUM_ITEMS, NUM_ITEMS);
    }
    ~this()
    {
        delete m_semaphore;
    }

public:
    static void X_hello(X x)
    {
printf("Hello from within the XFactory\n\n");
    }

    static void X_Acquire(out X x, out int key)
    {
printf("X_Acquire\n");
        x = null;
        key = 1;

        sm_semaphore.wait();
    }
    static void X_Release(X x, out int key)
    {
      key = 0;

        sm_semaphore.release();
    }

private:
    enum { NUM_ITEMS = 5 };

    static Semaphore    sm_semaphore;
};

auto class XUser
{
public:
    this()
    {
        m_x = null;
        m_key = 0;

printf("1");
        XFactory.X_hello(m_x);    // ** <== This call works fine
printf("2");
        XFactory.X_Acquire(m_x, m_key);    // ** <== This call crashes, if
both are out params
printf("3");
    }
    ~this()
    {
printf("4");
        if(m_key != 0)
        {
            XFactory.X_Release(m_x, m_key);
        }
    }

private:
    X   m_x;
    int m_key;
};

int worker_proc(void *_arg)
{
//printf("Entering the thread\n");

    ThreadInfo  threadinfo  =   (ThreadInfo)(_arg);
    int         i;

    for(i = 0; i < threadinfo.cIterations; ++i)
    {
        auto XUser  user = new XUser;           // Acquire the resource;
uses RAII

        // [snip]
    }

    return 0;
}
Apr 12 2003