Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with _beginthread

Problem with _beginthread

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpcsharpdata-structuresquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephan Pilz
    wrote on last edited by
    #1

    Hello, I have a semaphore controlled thread queue in my application. Now I have a problem to start my threads from the queue. After call of _beginthread I get a thread-id not equal -1 and not equal 0, but my thread is not started (no trace message from thread, no break in breakpoint). If I "help the application" with debugger "set next statement" to an other call of the _beginthread, I get an other thread-id (!= -1 && != 0), but thread is not started. In Taskmanager the threadcount is not inkremented. Who can help me? My application worked correcly under W2K. After compile the code with the .NET compiler the application works fine, besides on only one computer. But this computer is the machine, there must run the application :( Can it be a problem with not correct installed framework or libraries ? An important remember is, that the threats will be started correcly after restart the application. After some thread calls (between 10 and 100) it doesnt work. All threads terminated via _endthread() and in a good time (1-300 seconds). Thanks for any helping STP

    V 1 Reply Last reply
    0
    • S Stephan Pilz

      Hello, I have a semaphore controlled thread queue in my application. Now I have a problem to start my threads from the queue. After call of _beginthread I get a thread-id not equal -1 and not equal 0, but my thread is not started (no trace message from thread, no break in breakpoint). If I "help the application" with debugger "set next statement" to an other call of the _beginthread, I get an other thread-id (!= -1 && != 0), but thread is not started. In Taskmanager the threadcount is not inkremented. Who can help me? My application worked correcly under W2K. After compile the code with the .NET compiler the application works fine, besides on only one computer. But this computer is the machine, there must run the application :( Can it be a problem with not correct installed framework or libraries ? An important remember is, that the threats will be started correcly after restart the application. After some thread calls (between 10 and 100) it doesnt work. All threads terminated via _endthread() and in a good time (1-300 seconds). Thanks for any helping STP

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Post the declaration of the callback function. Post the call to _beginthreadex(). Kuphryn

      S 1 Reply Last reply
      0
      • V valikac

        Post the declaration of the callback function. Post the call to _beginthreadex(). Kuphryn

        S Offline
        S Offline
        Stephan Pilz
        wrote on last edited by
        #3

        Good morning kuphryn, there are more than one threadfuncs. All of this have the same prototyp: void ThreadFuncName (void *args); The application have one timer for each thread to start, but no thread should be run, if there an other running thread. To solve this, I use an self written thread-calling-queue. If a timer call, the corresponding thread would be add to my queue. The queue use a simple list and each element is a struct like this: typedef void (*ThreadFunc) (void *args); typedef struct _THREADLIST_STRUCT { ThreadFunc ThreadFkt; // Pointer to threadfunc long ThreadId; // ID for internal use _THREADLIST_STRUCT *next; // Pointer to next element } THREADLIST_STRUCT; And I have an other timer (1 second). He looks in me queue and is there a thread in and no other running thread, he starts the first element. unsigned long t_id = 0; t_id = _beginthread (m_Root->ThreadFkt, 0, m_pParent); if (t_id != -1) { // it's OK } else { / do an error message } Each access of the internal thread-list (AddThread, DelThread, StartThread, ...) is protected via a semaphore. Each thread remove himself from the queue at the end of thread and call _endthread(). As I already said, I works !!!, but after 10-100 thread-calls, it doesnt work again. The _beginthread () return a value != 0 and != -1 -> no error message. But the thread is'nt called. This effect exist only on one machine. The only one, there it should work in real life. This machine have: - W2K with latest SP's and Updates - complete installed Visual Studio .NET 2002 German (we have some problems with the compiler in the actual VS.NET !!) - SQLServer ODBC driver - pcAnywhere 10.5 Thanks Stephan

        V 1 Reply Last reply
        0
        • S Stephan Pilz

          Good morning kuphryn, there are more than one threadfuncs. All of this have the same prototyp: void ThreadFuncName (void *args); The application have one timer for each thread to start, but no thread should be run, if there an other running thread. To solve this, I use an self written thread-calling-queue. If a timer call, the corresponding thread would be add to my queue. The queue use a simple list and each element is a struct like this: typedef void (*ThreadFunc) (void *args); typedef struct _THREADLIST_STRUCT { ThreadFunc ThreadFkt; // Pointer to threadfunc long ThreadId; // ID for internal use _THREADLIST_STRUCT *next; // Pointer to next element } THREADLIST_STRUCT; And I have an other timer (1 second). He looks in me queue and is there a thread in and no other running thread, he starts the first element. unsigned long t_id = 0; t_id = _beginthread (m_Root->ThreadFkt, 0, m_pParent); if (t_id != -1) { // it's OK } else { / do an error message } Each access of the internal thread-list (AddThread, DelThread, StartThread, ...) is protected via a semaphore. Each thread remove himself from the queue at the end of thread and call _endthread(). As I already said, I works !!!, but after 10-100 thread-calls, it doesnt work again. The _beginthread () return a value != 0 and != -1 -> no error message. But the thread is'nt called. This effect exist only on one machine. The only one, there it should work in real life. This machine have: - W2K with latest SP's and Updates - complete installed Visual Studio .NET 2002 German (we have some problems with the compiler in the actual VS.NET !!) - SQLServer ODBC driver - pcAnywhere 10.5 Thanks Stephan

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          Interesting. I think the problem is m_Root points to an invalid memory address. You do not need to call_endthread(). Let the thread end on its on. If you keep track of it via a handle, then close the handle. Kuphryn

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups