Commits

Anonymous committed 72ddbdb

#96: mainlining directly

  • Participants
  • Parent commits 1ebd081

Comments (0)

Files changed (3)

 
 
 #
+# Runs the given function in a thread sharing the current global namespace
+#
+def runInThread(f):
+    """__NATIVE__
+    PmReturn_t retval;
+    pPmObj_t pf;
+
+    /* If wrong number of args, raise TypeError */
+    if (NATIVE_GET_NUM_ARGS() != 1)
+    {
+        PM_RAISE(retval, PM_RET_EX_TYPE);
+        return retval;
+    }
+
+    /* If arg is not a function, raise TypeError */
+    pf = NATIVE_GET_LOCAL(0);
+    if (OBJ_GET_TYPE(*pf) != OBJ_TYPE_FXN)
+    {
+        PM_RAISE(retval, PM_RET_EX_TYPE);
+        return retval;
+    }
+
+    retval = interp_addThread((pPmFunc_t)pf);
+    return retval;
+    """
+    pass
+
+
+#
 # Returns the number of milliseconds since the PyMite VM was initialized
 #
 def time():

src/tests/system/t096.c

+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * System Test 096
+ *
+ * Test for issue #96:
+ * Create library function to spawn a new thread
+ *
+ * Log
+ * ---
+ *
+ * 2007/02/07   #96: First
+ */
+
+#include "pm.h"
+#include "stdio.h"
+
+
+extern unsigned char usrlib_img[];
+
+
+int main(void)
+{
+    PmReturn_t retval;
+
+    retval = pm_init(MEMSPACE_FLASH, usrlib_img);
+    PM_RETURN_IF_ERROR(retval);
+
+    retval = pm_run((uint8_t *)"t096");
+    pm_reportResult(retval);
+    return (int)retval;
+}

src/tests/system/t096.py

+# PyMite - A flyweight Python interpreter for 8-bit microcontrollers and more.
+# Copyright 2002 Dean Hall
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# System Test 096
+#
+# Test for issue #96:
+# Create library function to spawn a new thread
+#
+
+import sys
+
+sharedVar = 42
+
+
+def f1():
+    global sharedVar
+    while sharedVar == 42:
+        print "f1: sharedVar is ", sharedVar
+    print "f1: sharedVar is ", sharedVar
+
+    
+def f2():
+    global sharedVar
+    print "f2: killing time..."
+    for i in range(32):
+        print i,
+    print
+    print "f2: setting sharedVar to 99"
+    sharedVar = 99
+
+sys.runInThread(f1)
+sys.runInThread(f2)