Results 1 to 4 of 4

Thread: Threading Issue

  1. #1
    dtogias is offline Registered User
    Name: Dimitris Togias
    Organization: NTUA
    Project: Building a custom server
    Join Date
    Dec 2008
    Posts
    2

    Threading Issue

    I'm trying to use class Thread from the IceUtils.dll and when i create a new thread i'm always getting an unhandled exception. The situation is like this:

    class CReaderThread : public IceUtil::Thread
    {
    void run() { }
    }

    class CWriterThread : public IceUtil::Thread
    {
    void Start() {
    _ThreadB = new CReaderThread();

    this->start();
    }

    void Stop() {
    //Stop _ThreadB
    _ThreadB.getThreadControl().join();

    //Stop this (class WriterThread)
    }

    CReaderThreadPtr _ThreadB;
    }


    The issue is that when i call the CWriterThread Start method for the first time the 2 threads start normally. Then i call the Stop function and everything is OK. But if i call for a second time the Start method of the CWriteThread the i get an exception on the line that creates the _ThreadB = new CReaderThread().
    If i comment out the line: this->start();,
    then i can call the Start and Stop methods as many times as i want.

    Maybe i have misunderstood something in the way that i should be using the IceUtil::Thread class.

    DT

  2. #2
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Dimitris,

    Welcome to our forums.

    Your code fragment is incomplete since you don't show where you start _ThreadB. However, the issue appears to be that you're trying to reuse a Thread object--start a thread with this object, stop the thread, and then restart it. Our Thread class does not support this usage: each object is for "one time" use: if you want to create and start a new thread, you need to create a new Thread object.

    Best regards,
    Bernard
    Bernard Normier
    ZeroC, Inc.

  3. #3
    dtogias is offline Registered User
    Name: Dimitris Togias
    Organization: NTUA
    Project: Building a custom server
    Join Date
    Dec 2008
    Posts
    2
    Yes you are right i forgot to include a line. Here is the complete code.

    class CReaderThread : public IceUtil::Thread
    {
    void run() { }
    }

    class CWriterThread : public IceUtil::Thread
    {
    void Start() {
    _ThreadB = new CReaderThread();
    _ThreadB->start();

    this->start();
    }

    void Stop() {
    //Stop _ThreadB
    _ThreadB.getThreadControl().join();

    //Stop this (class WriterThread)
    }

    CReaderThreadPtr _ThreadB;
    }

    The issue is that i'm getting the unhandled exception when i call _ThreadB->start not when i call this->start. That was the reason that i was puzzled.
    Thanks for you reply.

    DT

  4. #4
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Quote Originally Posted by dtogias View Post
    The issue is that i'm getting the unhandled exception when i call _ThreadB->start not when i call this->start.
    You should enclose your code in a try/catch block to avoid unhandled exceptions. Here, the exception was IceUtil::ThreadStartedException.

    Cheers,
    Bernard
    Bernard Normier
    ZeroC, Inc.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. AMD callbacks and threading
    By kwaclaw in forum Help Center
    Replies: 2
    Last Post: 05-22-2008, 11:00 AM
  2. Blocking functions and multi threading
    By nickadamson in forum Help Center
    Replies: 1
    Last Post: 02-04-2008, 10:52 AM
  3. File transfer and threading.
    By EmmanuelOga in forum Help Center
    Replies: 3
    Last Post: 08-15-2006, 09:41 AM
  4. c++ threading example docs
    By skropp in forum Help Center
    Replies: 3
    Last Post: 02-01-2006, 03:36 AM
  5. threading and proxy question
    By g00fy in forum Help Center
    Replies: 2
    Last Post: 01-04-2006, 04:18 PM

Posting Permissions

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