about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--channel.mu4
-rw-r--r--mu.arc3
-rw-r--r--mu.arc.t28
3 files changed, 27 insertions, 8 deletions
diff --git a/channel.mu b/channel.mu
index d58f4546..8e03cdc2 100644
--- a/channel.mu
+++ b/channel.mu
@@ -41,7 +41,7 @@
 (function main [
   (chan:channel-address <- init-channel 3:literal)
   ; create two background 'routines' that communicate by a channel
-  (fork consumer:fn nil:literal/globals chan:channel-address)
-  (fork producer:fn nil:literal/globals chan:channel-address)
+  (fork consumer:fn nil:literal/globals nil:literal/limit chan:channel-address)
+  (fork producer:fn nil:literal/globals nil:literal/limit chan:channel-address)
   (sleep for-some-cycles:literal 2000:literal)  ; wait for forked routines to effect the transfer
 ])
diff --git a/mu.arc b/mu.arc
index 29068bc5..786c4e2a 100644
--- a/mu.arc
+++ b/mu.arc
@@ -571,8 +571,9 @@
                   (run (v arg.0))
                 fork
                   ; args: fn globals-table args ...
-                  (let routine  (apply make-routine (m arg.0) (map m (nthcdr 2 arg)))
+                  (let routine  (apply make-routine (m arg.0) (map m (nthcdr 3 arg)))
                     (= rep.routine!globals (when (len> arg 1) (m arg.1)))
+                    (= rep.routine!limit (when (len> arg 2) (m arg.2)))
                     (enq routine running-routines*))
                 assert
                   (unless (m arg.0)
diff --git a/mu.arc.t b/mu.arc.t
index 0b20d19a..3cc99e18 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -2791,7 +2791,7 @@
 (new-trace "fork-with-args")
 (add-code
   '((function f1 [
-      (fork f2:fn nil:literal/globals 4:literal)
+      (fork f2:fn nil:literal/globals nil:literal/limit 4:literal)
      ])
     (function f2 [
       (2:integer <- next-input)
@@ -2806,7 +2806,7 @@
   '((function f1 [
       (default-space:space-address <- new space:literal 5:literal)
       (x:integer <- copy 4:literal)
-      (fork f2:fn nil:literal/globals x:integer)
+      (fork f2:fn nil:literal/globals nil:literal/limit x:integer)
       (x:integer <- copy 0:literal)  ; should be ignored
      ])
     (function f2 [
@@ -2825,7 +2825,7 @@
     (function main [
       (default-space:space-address <- new space:literal 5:literal)
       (2:integer <- copy 4:literal)
-      (fork f1:fn default-space:space-address/globals)
+      (fork f1:fn default-space:space-address/globals nil:literal/limit)
      ])))
 (run 'main)
 (each routine completed-routines*
@@ -2833,6 +2833,24 @@
 (if (~iso memory*.1 4)
   (prn "F - fork can take a space of global variables to access"))
 
+(reset)
+(new-trace "fork-limit")
+(add-code
+  '((function f1 [
+      { begin
+        (loop)
+      }
+     ])
+    (function main [
+      (fork f1:fn nil:literal/globals 30:literal/limit)
+     ])))
+(= scheduling-interval* 5)
+(run 'main)
+(each routine completed-routines*
+  (awhen rep.routine!error (prn "error - " it)))
+(when (ran-to-completion 'f1)
+  (prn "F - fork can specify a maximum cycle limit"))
+
 ; The scheduler needs to keep track of the call stack for each routine.
 ; Eventually we'll want to save this information in mu's address space itself,
 ; along with the types array, the magic buffers for args and oargs, and so on.
@@ -3142,7 +3160,7 @@
   '((function consumer [
       (default-space:space-address <- new space:literal 30:literal)
       (chan:channel-address <- init-channel 3:literal)  ; create a channel
-      (fork producer:fn nil:literal/globals chan:channel-address)  ; fork a routine to produce a value in it
+      (fork producer:fn nil:literal/globals nil:literal/limit chan:channel-address)  ; fork a routine to produce a value in it
       (1:tagged-value/raw <- read chan:channel-address)  ; wait for input on channel
      ])
     (function producer [
@@ -3169,7 +3187,7 @@
   '((function consumer [
       (default-space:space-address <- new space:literal 30:literal)
       (1:channel-address <- init-channel 3:literal)  ; create a channel
-      (fork producer:fn default-space:space-address/globals)  ; pass it as a global to another routine
+      (fork producer:fn default-space:space-address/globals nil:literal/limit)  ; pass it as a global to another routine
       (1:tagged-value/raw <- read 1:channel-address)  ; wait for input on channel
      ])
     (function producer [
id='n291' href='#n291'>291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533