You Are Here:

Community: Developer Discussion Boards

#1 Old Help! Multi thread problems - 2009-06-23, 13:13

Join Date: Jun 2009
Posts: 4
tq00oqi
Offline
Registered User
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.
Reply With Quote

#2 Old Smile Re: Help! Multi thread problems - 2009-06-23, 13:46

Join Date: Jul 2008
Posts: 471
Location: Pakistan
sajisoft's Avatar
sajisoft
Offline
Regular Contributor
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


"The purpose of software engineering is to control complexity, not to create it."

--§ajid Ali Anjum--
http://sajisoft.wordpress.com/
Reply With Quote

#3 Old Re: Help! Multi thread problems - 2009-06-23, 16:43

Join Date: Jun 2009
Posts: 4
tq00oqi
Offline
Registered User
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.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Emulator crash immediatly after launched, SDK of S60 3nd loopfinder Symbian Tools & SDKs 20 2009-07-26 23:36
exit() and _Exit() for multi thread Open C app kcomex Open C/C++ 3 2009-04-20 15:40
S60 5th Edition emulator startup problem gopitek General Symbian C++ 1 2009-01-13 17:51
Multi RPointerArray lots of problems sirtomash General Symbian C++ 8 2008-12-10 08:33
Multi Thread problem Segev General Symbian C++ 4 2007-05-03 20:38

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia