Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C threading question: accept() being called twice

  • 17-10-2013 9:38pm
    #1
    Closed Accounts Posts: 3,981 ✭✭✭


    The following code is being called twice, *sometmies*, when I make a single request. Does anyone have any idea why?

    The numbers are line numbers. Code is here:
    while(1)
    {
              if ( (connfd = accept(listenfd, (struct sockaddr*)NULL, NULL) ) >=0) {
                  pthread_t thread;
                  pthread_create(&thread, NULL, (void *) processConnection, (void*) &connfd);
                  pthread_join(thread, NULL);
    }
    


Comments

  • Closed Accounts Posts: 3,981 ✭✭✭[-0-]


    >= did it. Heh. Strange thing is before I added threading that wasn't there. Damn these fat fingers!


  • Registered Users, Registered Users 2 Posts: 434 ✭✭TheBoffin


    Easy do at this time of night. Having an argument with a listview and friend values at the moment - Coffee Time!


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    I'm guessing some kind of server? I hope you don't mind some unsolicited advice for the future. Don't spawn a thread per request, create a pool of threads in advance, and when a request comes in, let the next free thread handle it.


  • Closed Accounts Posts: 3,981 ✭✭✭[-0-]


    I'm guessing some kind of server? I hope you don't mind some unsolicited advice for the future. Don't spawn a thread per request, create a pool of threads in advance, and when a request comes in, let the next free thread handle it.

    Interesting. I was thinking of using the max threads allowed for a process, but I want this server to be very light weight so I'll probably limit the number of threads to the number of concurrent connections I allow, which right now is only 100. I'll create a threadpool wrapper for pthread. Cheers!


Advertisement