×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    4

    Help! Multi thread problems

    import appuifw, thread, e32, os

    t1,t2=0,0

    def a():
    global t1
    t1=os.getpid()
    while True:
    print "thanks"

    def b():
    global t2
    t2=os.getpid()
    while True:
    print "abc"

    def start():
    thread.start_new_thread(a,())
    thread.start_new_thread(b,())


    def stop():
    os.popen("kill -9 "+str(t1))

    appuifw.app.menu=[(u"Start", start),
    (u"stop", stop)]

    app_lock = e32.Ao_lock()
    app_lock.wait()

    here is an example code which simply starts two thread a() and b() when you select start from the menu, and stop a() when you select stop from the menu. However, my problem is how can I kill thread a(). Functions like os.kill,os.popen etc are just not available in pys60. Any ideas? It doesn't seem to be a difficult problem but i just can't find the answer on the web.

  2. #2
    Nokia Developer Champion
    Join Date
    Jul 2008
    Location
    Pakistan
    Posts
    1,065

    Smile Re: Help! Multi thread problems

    Quite easy.Just put a condition variable .Try something like this:
    Code:
    import appuifw, thread, e32, os
    
    t1,t2=0,0
    running_a = 1
    running_b = 1
    def a():
        global t1, running_a
        t1=os.getpid()
        while running_a == 1:
            print "thanks"
    
    def b():
        global t2, running_b
        t2=os.getpid()
        while running_b == 1:
            print "abc"
        
    def start():
        thread.start_new_thread(a,())
        thread.start_new_thread(b,())
        
        
    def stop():
        global running_a, running_b
        running_a = 0 //exits the thread a
        running_b = 0 //exits the thread b
    
    appuifw.app.menu=[(u"Start", start),
                      (u"stop", stop)]
    
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Thats it. Hope it helps u..

    Best Regards,
    SajiSoft

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    4

    Re: Help! Multi thread problems

    Quote Originally Posted by sajisoft View Post
    Quite easy.Just put a condition variable .Try something like this:
    Code:
    import appuifw, thread, e32, os
    
    t1,t2=0,0
    running_a = 1
    running_b = 1
    def a():
        global t1, running_a
        t1=os.getpid()
        while running_a == 1:
            print "thanks"
    
    def b():
        global t2, running_b
        t2=os.getpid()
        while running_b == 1:
            print "abc"
        
    def start():
        thread.start_new_thread(a,())
        thread.start_new_thread(b,())
        
        
    def stop():
        global running_a, running_b
        running_a = 0 //exits the thread a
        running_b = 0 //exits the thread b
    
    appuifw.app.menu=[(u"Start", start),
                      (u"stop", stop)]
    
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Thats it. Hope it helps u..

    Best Regards,
    SajiSoft
    Wow, you really solved my problem. You also remind me my concurrency lesson in the uni. Thank you very much.

Similar Threads

  1. Emulator crash immediatly after launched, SDK of S60 3nd
    By loopfinder in forum Symbian Tools & SDKs
    Replies: 27
    Last Post: 2011-01-30, 14:06
  2. S60 5th Edition emulator startup problem
    By gopitek in forum Symbian
    Replies: 2
    Last Post: 2010-09-08, 08:05
  3. exit() and _Exit() for multi thread Open C app
    By kcomex in forum Open C/C++
    Replies: 3
    Last Post: 2009-04-20, 14:40
  4. Multi RPointerArray lots of problems
    By sirtomash in forum Symbian
    Replies: 8
    Last Post: 2008-12-10, 07:33
  5. Multi Thread problem
    By Segev in forum Symbian
    Replies: 4
    Last Post: 2007-05-03, 19:38

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×