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. Linux Programming
  4. More advise wanted - how to run TWO loops ?

More advise wanted - how to run TWO loops ?

Scheduled Pinned Locked Moved Linux Programming
graphicsgame-devsysadmindebugginghelp
8 Posts 6 Posters 25 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    Here is the latest snag I am against. Main part of my application is to WAIT to receive data. In fancy techno talk - I have a server in "accept" state - waiting to receive data - hence processing is stopped. The data received is processed and then passed to OpenGL - OpenGL is in similar waiting state "they" call glutMainLoop(); Obviously unworkable situation - cannot have two waiting state. . Found "fork" which creates two processes , but they do not share variables. Looking at socketpair to solve that "problem". Now it looks as proverbial "long way around the barn"... Any other "professional" suggestion ? Not really sure how to debug such setup - jumping between processes , but willing to try it.

    P L M CPalliniC U 5 Replies Last reply
    0
    • V Vaclav_

      Here is the latest snag I am against. Main part of my application is to WAIT to receive data. In fancy techno talk - I have a server in "accept" state - waiting to receive data - hence processing is stopped. The data received is processed and then passed to OpenGL - OpenGL is in similar waiting state "they" call glutMainLoop(); Obviously unworkable situation - cannot have two waiting state. . Found "fork" which creates two processes , but they do not share variables. Looking at socketpair to solve that "problem". Now it looks as proverbial "long way around the barn"... Any other "professional" suggestion ? Not really sure how to debug such setup - jumping between processes , but willing to try it.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      One word to read up on...

      threads

      Cheers, Peter

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      1 Reply Last reply
      0
      • V Vaclav_

        Here is the latest snag I am against. Main part of my application is to WAIT to receive data. In fancy techno talk - I have a server in "accept" state - waiting to receive data - hence processing is stopped. The data received is processed and then passed to OpenGL - OpenGL is in similar waiting state "they" call glutMainLoop(); Obviously unworkable situation - cannot have two waiting state. . Found "fork" which creates two processes , but they do not share variables. Looking at socketpair to solve that "problem". Now it looks as proverbial "long way around the barn"... Any other "professional" suggestion ? Not really sure how to debug such setup - jumping between processes , but willing to try it.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Multiple processes can happily share variables in global memory. They just need to use semaphores or mutexes to synchronise their access. Just about every application running on the web, on desktops, phones etc. uses these features.

        1 Reply Last reply
        0
        • V Vaclav_

          Here is the latest snag I am against. Main part of my application is to WAIT to receive data. In fancy techno talk - I have a server in "accept" state - waiting to receive data - hence processing is stopped. The data received is processed and then passed to OpenGL - OpenGL is in similar waiting state "they" call glutMainLoop(); Obviously unworkable situation - cannot have two waiting state. . Found "fork" which creates two processes , but they do not share variables. Looking at socketpair to solve that "problem". Now it looks as proverbial "long way around the barn"... Any other "professional" suggestion ? Not really sure how to debug such setup - jumping between processes , but willing to try it.

          M Offline
          M Offline
          Member 14773037
          wrote on last edited by
          #4

          fork() and signal() - that's what I used in the 1980's and 1990's before POSIX 4 (later POSIX 1a now pthreads and more recently, threads native to C11 and C++11) came into being. This includes sigwait(), sigpause(), sigsuspend(), etc. Some of these work with threads. It might be possible to emulate the functionality of all concurrency primitives with these elements alone. You can look under the POSIX Standard for more information The Open Group Base Specifications Issue 7, 2018 edition[^] There is already a multi-platform Pause-Resume thread framework on this site. That's what landed me on this web site. It's right here Data Processing Thread with the Pause/Resume Functionality[^]

          1 Reply Last reply
          0
          • V Vaclav_

            Here is the latest snag I am against. Main part of my application is to WAIT to receive data. In fancy techno talk - I have a server in "accept" state - waiting to receive data - hence processing is stopped. The data received is processed and then passed to OpenGL - OpenGL is in similar waiting state "they" call glutMainLoop(); Obviously unworkable situation - cannot have two waiting state. . Found "fork" which creates two processes , but they do not share variables. Looking at socketpair to solve that "problem". Now it looks as proverbial "long way around the barn"... Any other "professional" suggestion ? Not really sure how to debug such setup - jumping between processes , but willing to try it.

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            I would second Peter_in_2780 suggestion. With modern C++ (assuming you are using C++) it is as friendly as shown in the sample code of this page: std::thread::thread - cppreference.com[^].

            In testa che avete, signor di Ceprano?

            V 1 Reply Last reply
            0
            • CPalliniC CPallini

              I would second Peter_in_2780 suggestion. With modern C++ (assuming you are using C++) it is as friendly as shown in the sample code of this page: std::thread::thread - cppreference.com[^].

              V Offline
              V Offline
              Vaclav_
              wrote on last edited by
              #6

              I generally use KISS approach. The task is to have two event "loops" , one monitoring the bluetooth input and the other processing and displaying results. "fork" does the job. Besides - as I continue to build the app it is not pure C++, such as OpenGL is "just" C.

              CPalliniC 1 Reply Last reply
              0
              • V Vaclav_

                I generally use KISS approach. The task is to have two event "loops" , one monitoring the bluetooth input and the other processing and displaying results. "fork" does the job. Besides - as I continue to build the app it is not pure C++, such as OpenGL is "just" C.

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                KISS can be subjective. In my opinion, fork is not more KISS than threads, because you have to go through IPC.

                In testa che avete, signor di Ceprano?

                1 Reply Last reply
                0
                • V Vaclav_

                  Here is the latest snag I am against. Main part of my application is to WAIT to receive data. In fancy techno talk - I have a server in "accept" state - waiting to receive data - hence processing is stopped. The data received is processed and then passed to OpenGL - OpenGL is in similar waiting state "they" call glutMainLoop(); Obviously unworkable situation - cannot have two waiting state. . Found "fork" which creates two processes , but they do not share variables. Looking at socketpair to solve that "problem". Now it looks as proverbial "long way around the barn"... Any other "professional" suggestion ? Not really sure how to debug such setup - jumping between processes , but willing to try it.

                  U Offline
                  U Offline
                  User 13269747
                  wrote on last edited by
                  #8

                  Follow the directions here:

                  man pthread_create

                  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