Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
multi threaded script
- X-seq: zsh-users 14521
- From: Baptiste Daroussin <baptiste.daroussin@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: multi threaded script
- Date: Tue, 3 Nov 2009 16:34:57 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=MMzbVoNBvNM4PY2hvVdM2JsoZ1OdzXLpSSi6Z/Vpers=; b=uS6un8WlyI4t6cge7X4SqpVEzBWRrH1+IdEf+tmjOJGPcIQTkyYzp8x0RdOSlpmOPe QoScpcJIQuYvRF2Cc49SHkxCudyiZp1RTo81f0ah+I8/p0g9NO44+enHxyWVNw2f2ryM x/w9toHMPo8UPqjr4GOfJenpyO4zb14s6rmOc=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=CNggJXvO/pY0v6cEDKYbMnUkvtr71nSuzyIt6HSMfOl/dW2kAlF2UAV5hdOgtRnYio ZX47SBGXhtXc9luaSaKEu4U0Can7DWd8xMqKyrWIoNMCOl7oWiJ0fK3ZZFpNORiDGgQa Be/Osn1CeRVAQK9Fzs2UERA0G5rZc5hrh5Spo=
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hi,
I wanted to write a script that needs to be multithreaded, for example
an UI in zsh/curses that does things in background while the UI is
still responsive.
As I found nothing to be able to execute parallelize processes in zsh
(I'm not speaking of fork()) I began to wrote a small and dirty
pthread module for zsh it was quite easy, currently I only implemented
:
pthread_create, pthread_join, pthread_mutex_lock pthread_mutex_unlock,
As soon as I tryed to use it some problems occurs which shows me (in
fact IRC guys show this to me :)) that pthreads is not a good idea
because of global variables.
So my question as a zsh/zthread module won't make sense in zsh, what
would make sense to a able to achieve this stupid example :
zmodload zsh/zthread
zmutex init lock1
integer toto
toto=11
thread1() {
zmutex lock lock1
print "Hello from thread1 $toto"
toto+=1
zmutex unlock lock1
sleep 5
zmutex lock lock1
print "again thread1 $toto"
zmutex unlock lock1
return
}
thread2() {
zmutex lock lock1
print "Hello from thread2 $toto"
toto+=2
zmutex unlock lock1
sleep 5
zmutex lock lock1
print "again thread2 $toto"
zmutex unlock lock1
return
}
zthread create thr1 thread1
zthread create thr2 thread2
zthread join thr1
zthread join thr2
for information zthread sometime works with this, sometimes shows
garbage, sometimes it exit with pthread fatal error.
Perhaps it is not a good idea to use zsh for that kind of purpose.
regards,
Bapt
Messages sorted by:
Reverse Date,
Date,
Thread,
Author