Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:49:01+00:00 2026-06-03T05:49:01+00:00

I am implementing a program that launches 4 threads. The functions are: void* SOURCE_in(struct

  • 0

I am implementing a program that launches 4 threads.

The functions are:

void* SOURCE_in(struct SOURCE_1*);
void* SOURCE_out(struct SOURCE*);
void* SINK_out(struct SINK_1*);
void* SINK_in(struct SINK*);

The functions allow communication between 4 blocks.
The Block 1 communicates with block 2.
Block 2 share information with third block.
Block 3 communicates information with the Block 4.

My problem is in main.c

int main(int argc, char** argv){

    extern int p, e_source, e_sink_1, l_sink, l_source_1, flag, ctr_source;
    extern int ctr_source_1, ctr_sink, ctr_sink1;

        SOURCE source;      /*C struct*/
        SINK sink;          /*C struct*/
        SOURCE_1 source_1;  /*C struct*/
        SINK_1 sink_1;      /*C struct*/

        HANDLE CHT[4];

        p = 0;
        e_source =  flag = 0;
        l_sink = e_sink_1 = l_source_1 = 1;
        max = 5;
        ctr_source = ctr_source_1 = ctr_sink = ctr_sink_1 = 0;

        /*Initialize FIFO*/
        F *f1 = fifo_init(10);
        F *f2 = fifo_init(10);

        /*Connect FIFO and modules*/
        source.output_source = f1;
        sink.input_sink = f1;

        sink_1.output_sink = f2;
        source_1.input_source = f2;

        /*Create Threads*/
        CHT[0] = (HANDLE)_beginthread((void (*)(void *))&SOURCE_out, 0, &f1);
        CHT[1] = (HANDLE)_beginthread((void (*)(void *))&SINK_in, 0, &f1);
        CHT[2] = (HANDLE)_beginthread((void (*)(void *))&SINK_out, 0, &f2);
        CHT[3] = (HANDLE)_beginthread((void (*)(void *))&SOURCE_in, 0, &f2);

        /* Wait until all threads have terminated */

        WaitForSingleObject(CHT[0], INFINITE);
        WaitForSingleObject(CHT[1], INFINITE);
        WaitForSingleObject(CHT[2], INFINITE);
        WaitForSingleObject(CHT[3], INFINITE);

        getchar();

        return 0;}

I read that WaitForSingleObject function does not work with _beginthread….
But my functions are not the type nunsigned __stdcall…

I build the programm withou errors, and I use breakpoints to test it and it was ok.
when I compile I have this problem:

The thread ‘Win32 Thread’ (0x11ec) has exited with code 0 (0x0).
The thread ‘Win32 Thread’ (0x918) has exited with code 0 (0x0).
The thread ‘Win32 Thread’ (0x8a4) has exited with code 0 (0x0).
The thread ‘Win32 Thread’ (0x2a8) has exited with code -1073741510 (0xc000013a).
The thread ‘Win32 Thread’ (0x12f8) has exited with code -1073741510 (0xc000013a).
The program ‘[3984] SW=SW.exe: Native’ has exited with code -1073741510 (0xc000013a).

The program never gets to the function getchar()

Before doing this program, I made a program that made communication between two blocks, one read and the other one write. In that case, I had no problems.

If I don not use the function WaitForSingleObject the problem disappears, but my program, almost all times, stops before finishing.

The function that each thread use, stops with a break.
But i want the other ones to continue until its break apear..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:49:03+00:00Added an answer on June 3, 2026 at 5:49 am

    The documentation of _beginthread explains that you cannot use one of the wait functions:

    The following sample code demonstrates how you can use the thread handle returned by _beginthreadex with the synchronization API WaitForSingleObject. The main thread waits for the second thread to terminate before it continues. When the second thread calls _endthreadex, it causes its thread object to go to the signaled state. This allows the primary thread to continue running. This cannot be done with _beginthread and _endthread, because _endthread calls CloseHandle, destroying the thread object before it can be set to the signaled state.

    And this text also gives you the solution, namely to use _beginthreadex instead.

    I think you are alluding to this in the question when you say that

    but my functions are not __stdcall

    You simply have to change your functions to use the __stdcall calling convention.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently implementing a program that requires me to handle threads and process.
I'm implementing a process elevation helper for Windows. It's a program that will run
I tried implementing a sorting program in mapreduce such that I have just the
I'm implementing a c# program that should automatize a Mono-alphabetic substitution cipher. The functionality
So, I'm implementing a program with multiple threads (pthreads), and I am looking for
I found a wonderful open source Java program that I'm translating into C#. The
I'm implementing a very simple FTP server program that is able to retrieve and
This is my first C program that does something useful. I'm implementing a generic
I'm implementing a program that needs to serialize and deserialize large objects, so I
I'm implementing a C++ program that can programmatically instantiate objects given an input file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.