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 8476433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:10:41+00:00 2026-06-10T18:10:41+00:00

I’ve searched the internet for a while now and found different solutions but then

  • 0

I’ve searched the internet for a while now and found different solutions but then all don’t really work or are to complicated for my use.
I used C++ until 2 years ago so it might be a bit rusty 😀

I’m currently writing a program that posts data to an URL. It only posts the data nothing else.
For posting the data I use curl, but it blocks the main thread and while the first post is still running there will be a second post that should start.
In the end there are about 5-6 post operations running at the same time.

Now I want to push the posting with curl into another thread. One thread per post.
The thread should get a string parameter with the content what to push.

I’m currently stuck on this. Tried the WINAPI for windows but that crashes on reading the parameter. (the second thread is still running in my example while the main thread ended (waiting on system(“pause”)).

It would be nice to have a multi plattform solution, because it will run under windows and linux!

Heres my current code:

#define CURL_STATICLIB
#include <curl/curl.h>
#include <curl/easy.h>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#if defined(WIN32)
    #include <windows.h>
#else
    //#include <pthread.h>
#endif

using namespace std;

void post(string post) { // Function to post it to url
    CURL *curl; // curl object
    CURLcode res; // CURLcode object
    curl = curl_easy_init(); // init curl
    if(curl) { // is curl init
        curl_easy_setopt(curl, CURLOPT_URL, "http://10.8.27.101/api.aspx"); // set url
        string data = "api=" + post; // concat post data strings
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); // post data
        res = curl_easy_perform(curl); // execute
        curl_easy_cleanup(curl); // cleanup
    } else {
        cerr << "Failed to create curl handle!\n";
    }
}

#if defined(WIN32)
    DWORD WINAPI thread(LPVOID data) { // WINAPI Thread
        string pData = *((string*)data); // convert LPVOID to string [THIS FAILES]
        post(pData); // post it with curl
    }
#else
    // Linux version
#endif

void startThread(string data) { // FUnction to start the thread
    string pData = data; // some Test
    #if defined(WIN32)
        CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread, &pData, 0, NULL); // Start a Windows thread with winapi
    #else
        // Linux version
    #endif
}

int main(int argc, char *argv[]) {
    // The post data to send
    string postData = "test1234567890";
    startThread(postData); // Start the thread
    system("PAUSE"); // Dont close the console window
    return EXIT_SUCCESS;
}

Has anyone a suggestion?

Thanks for the help!

  • 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-10T18:10:43+00:00Added an answer on June 10, 2026 at 6:10 pm

    Use std::thread for threads. It’s a relatively new thing, part of the newest C++11 standard, but it will probably be the most portable way to do threads in the near future.

    See how easy it is to make 5 threads that will busy-wait (unless optimized by the compiler):

    #include<thread>
    #include<vector>
    
    int main()
    {
        std::vector<std::thread> threads;
        for (int i=0; i< 5; i++)
        {
             threads.push_back(std::thread([] () {
                  for (long long j=0; j < 1000000000000LL; j++) ;
             }));
        }
    
        for (auto & thread : threads)
        {
             thread.join();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question

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.