unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* un-determined behavior of asyncs
@ 2013-05-20 14:44 Chaos Eternal
  2013-05-20 18:37 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Chaos Eternal @ 2013-05-20 14:44 UTC (permalink / raw)
  To: guile-user, guile-devel

[-- Attachment #1: Type: text/plain, Size: 803 bytes --]

hi gurus,

I wrote a short code to inspect the behavior of asyncs,
and find that neither the running time nor the order of execution is determined,
in fact , i find that the execution order of asyncs are random.

I just want to understand whether this random execution order of
asyncs is designed or desired or not-specified ?

thanks, the code is attached, the output follows:

$ guile async.scm
t2
((13700 1136293857 1) (18024 1136289128 0) (11235 1136295519 4) (11375
1136295012 3) (11444 1136294540 2) (8011 1136297645 9) (7978
1136297254 8) (7932 1136296817 7) (7735 1136296394 6) (3380 1136295978
5))
t1
((4262 1136289128 0) (317 1136293857 1) (221 1136294540 2) (199
1136295012 3) (228 1136295519 4) (215 1136295978 5) (203 1136296394 6)
(183 1136296817 7) (191 1136297254 8) (214 1136297645 9))

[-- Attachment #2: async.scm --]
[-- Type: application/octet-stream, Size: 791 bytes --]


;;(use-modules (srfi srfi-18))
(use-modules (ice-9 threads))
(define mb (make-parameter '()))

(define some-thread 
  (call-with-new-thread
   (lambda ()
     (begin 
       (mb '())
       (let lp ((i 0)) (if (< i 500000000) (lp (+ 1 i))))
       (display 't2)
       (newline)
       (display (mb))
       (newline)))))

(let lp ((i 0)) (if (< i 50000000) (lp (+ 1 i))))

(define t1-res 
  (map
   (let ((t some-thread))
     (lambda (x)
       (let ((ct (get-internal-real-time)))
	 (system-async-mark
	  (lambda ()
	    (mb
	     (cons 
	      (list (- (get-internal-real-time) ct) ct x)
	      (mb)))
	    )
	  t)
	 (list (- (get-internal-real-time) ct) ct x))))
   (iota 10)))

;;(thread-join! some-thread)
(join-thread some-thread)
(display 't1)
(newline)
(display t1-res)
(newline)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: un-determined behavior of asyncs
  2013-05-20 14:44 un-determined behavior of asyncs Chaos Eternal
@ 2013-05-20 18:37 ` Andy Wingo
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Wingo @ 2013-05-20 18:37 UTC (permalink / raw)
  To: Chaos Eternal; +Cc: guile-user, guile-devel

On Mon 20 May 2013 16:44, Chaos Eternal <chaoseternal@shlug.org> writes:

> I just want to understand whether this random execution order of
> asyncs is designed or desired or not-specified ?

Your program has no synchronization so I am not sure what you expect it
to do.  There's not even any guarantee that the thread is running at
all, AFAICS.

You may have come upon a bug but I don't understand the test case very
well.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-05-20 18:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-20 14:44 un-determined behavior of asyncs Chaos Eternal
2013-05-20 18:37 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).