thread execution order

From: Axel Mittendorf (newsreply_at_transfertech.de)
Date: 09/30/04

  • Next message: Rembrandt Q Einstein: "Re: thread execution order"
    Date: Thu, 30 Sep 2004 15:33:06 +0200
    
    

    Hi, I have an app that writes text messages into a pipe and reads it out.
    Other programs write into this pipe too. Sometimes the pipe is full and
    my app freezes if it wants to write in that moment. It is not an option
    for me to open the pipe with O_NONBLOCK, so I thought I could
    use threads. Always when something shall be written into the pipe a new
    thread is created. These threads may hang on os.write, but they'll write out
    the data ASAP.
    See the example below (I substituted os.write with lock.acquire(1)).
    But if the pipe was full, three threads were created (all hang on os.write)
    and
    now the pipe is emptied, which one will write its data at first? The threads
    ordered by the time of thier creation (first no 1 then no 2,3,4 ... n) or
    just one of them
    (not ordered, maybe no4 then no1 and then no3)?
    I ask this since the order of the messages is important.

    # little example
    import threading

    class TO(object):
        def __init__(self):
            self.lock = threading.Lock()
            self.lock.acquire(0)
        def dowrite(self,s):
            self.lock.acquire(1) # this should be a blocking os.write
            print "dowrite:",s
            self.lock.release()
        def write(self,s):
            print "write:",s
            t = threading.Thread(target= self.dowrite,args=(s,))
            t.start()

    to = TO()
    to.write("one")
    to.write("two")
    to.write("three")
    to.lock.release()

    TIA, Axel Mittendorf


  • Next message: Rembrandt Q Einstein: "Re: thread execution order"

    Relevant Pages

    • [opensuse] Re: USER question
      ... how do you detect EOF on> the ... The only way to generate EOF on a pipe is to close the pipe. ... All use of the user alias is in a gosub and the gosub includes the user command that opens the pipe, and never closes it, relying on the fact that filepro doesn't actually spawn further instances of the target program when re-executing the same user command. ... If you try to read form user when the app isn't writing, you hang until the app sends you an end of line. ...
      (SuSE)
    • Re: BFS vs. mainline scheduler benchmarks and measurements
      ... the latest upstream scheduler tree on a testbox of mine. ... The app creates a pipe, and forks a child that blocks on reading from ...
      (Linux-Kernel)
    • Re: to be (readable) or not to be (readable), thats the question.
      ... I want my app to be robust and detect dumb processes. ... I kill a *child* of the process connected to. ... Now, if I send some instruction down the pipe (yes, the pipe is still ... Is there an explanation for getting pipe readable events in this case? ...
      (comp.lang.tcl)
    • Re: Connect a pipe from asynchronous pluggable protocol?
      ... But I ran into some problem when using the APP to connect. ... multi-threads that is created with NULL as security too, ... If you specify NULL for the security attributes structure then the pipe is ... discretionary access control lists. ...
      (microsoft.public.win32.programmer.kernel)
    • Re: pipes
      ... I have an app that will read an instrument about 10x a second. ... the data will read it from the pipe. ... for days without anyone reading it. ... pipe or any other data channel at these specified intervals. ...
      (comp.unix.programmer)