Results 1 to 5 of 5

Thread: threading?

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2006
    Location
    MN
    Posts
    7

    threading?

    Ok, this could be really hard, or really easy, here's my problem,I have data comming in through an ethernet cable from a device, this is done with sockets, fyi, the data is constantly flowing

    I am not sure with how the mainLoop of GL is set up, if it would just be a good idea to thread the whole handeling of the socket data, or not. Frankly, i have tried both, threading, and setting the idlefunc to the method that opens and handles the data.

    also, in the function that handels the IO im just called glutpostdisplay, and my glutdisplayfunc is the one that draws everything based on the data.

    I have a feeling that im screwing up the event queue somehow, any suggestions?


    ok ive have done some more reading, it looks like calling glutpostdisplay from a thread just wont cut it....tell me if this sounds right.....ill have a bool or something in the IO tread, and when new things are ready to be drawn, i set it to true....in my display func, which is also my glutidlefunc, i check for that bool, and if it is true, set, the bool back to false, and draw teh new data, since, there is only one thing here, i shouldnt even have to mutext it...right???

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: threading?

    Well if you have a display thread and an i/o thread you need to make sure there is communication of data between them and all the rendering gets done in the display thread. Whether you need synchronization and buffered communication between them is for you to determine.

    If you're not threaded then just calling the i/o in a glut callback is fine. Just be aware that you're not threaded doing that unless you launch a thread in there (not recommended).

    If you are threaded the you probably want to perform a data copy, or bool IPC in a callback (a bool would be a synchronization). You could make it 2-way or not depending on your circumstances.

    There are many strategies depending on the nature of the data and the timing & relative performance.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2006
    Location
    MN
    Posts
    7

    Re: threading?

    yeah, thats what i thought, right now, im just using the stl swap() function, because that is atomic, but anyway, the tread will swap, and the display with swap, and there is a conditional check in each thing, thus it is syncronized, I think i still might have to get a buffer going though, cause the data is comming it at around 75 frames of data per second...we shall see, thanks for the help

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: threading?

    The STL swap() function is not atomic.

    The simplest approach to synchronisation is using a mutex to protect access to shared variables. Unfortunately the API is different for each operating system.

    If you want a truly atomic swap, you'll have to write it yourself with assembler, but that's obviously architecture dependant, and also compiler dependant

  5. #5
    Senior Member Regular Contributor
    Join Date
    Jun 2006
    Location
    Edinburgh - Scotland
    Posts
    146

    Re: threading?

    There is a nice cross-platform thread class at
    Cross-platform thread class

    Part of it is a Mutex class which I've used on Windows and various Linux. It's just a couple of header files so it's simple to use. Though for the Thread class I've had to fix a couple syntax things for the newer (and stricter) g++.
    --Stuart.

Similar Threads

  1. FBO and threading
    By prisoner52 in forum OpenGL: Windows
    Replies: 5
    Last Post: 02-23-2011, 03:40 AM
  2. threading gtk and openGL
    By akashiraffee in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-07-2009, 09:57 AM
  3. LP: Multi-threading?
    By Dirk in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 06-27-2007, 02:48 PM
  4. Multi-threading
    By OldProgie in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-20-2005, 07:50 AM
  5. Threading
    By nagenderreddy in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 08-21-2003, 06:38 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
  •  
Proudly hosted by Digital Ocean