SB Implementing ScriptBasic Multi- Thread How to embed ScriptBasic multi-thread?

Slides:



Advertisements
Similar presentations
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Advertisements

Operating Systems Parallel Systems (Now basic OS knowledge)
Introduction to By Mati Yanko. Primary Goals of Java Portable Secured Object Oriented.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Server Architecture Models Operating Systems Hebrew University Spring 2004.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Systems Programming Course Gustavo Rodriguez-Rivera.
C and Data Structures Baojian Hua
VB in Context Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh Pittsburgh, Pa 15260
Memory Layout C and Data Structures Baojian Hua
Java and C++, The Difference An introduction Unit - 00.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
SB ScriptBasic Introduction to ScriptBasic There are more people writing programs in BASIC than the number of people capable programming.
1 MT258 Computer Programming and Problem Solving Unit 7.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
1 Confidential Enterprise Solutions Group Process and Threads.
SB Symbol table handling in ScriptBasic The Module sym.
1 Web Based Programming Section 8 James King 12 August 2003.
ECE 297 Concurrent Servers Process, fork & threads ECE 297.
1 Threads Chapter 11 from the book: Inter-process Communications in Linux: The Nooks & Crannies by John Shapley Gray Publisher: Prentice Hall Pub Date:
Object Oriented Programming (OOP) Lecture No. 11.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate.
SB How ScriptBasic works Introduction to ScriptBasic Modules.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
SB Syntax analysis How ScriptBasic performs Syntax analysis.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
CSC 322 Operating Systems Concepts Lecture - 7: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Threads. Readings r Silberschatz et al : Chapter 4.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
RealTimeSystems Lab Jong-Koo, Lim
Fiber Based Job Systems Seth England. Preemptive Scheduling Competition for resources Use of synchronization primitives to prevent race conditions in.
1 Introduction to Threads Race Conditions. 2 Process Address Space Revisited Code Data OS Stack (a)Process with Single Thread (b) Process with Two Threads.
MULTITHREADED PROGRAMMING Processes vs. Threads Process states and state transitions Hazards and Semaphores 1.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Processes and threads.
Process Tables; Threads
Process concept.
Object-Oriented Programming with Java
EE2E1. JAVA Programming Revision Lecture.
Multithreading Tutorial
Introduction Enosis Learning.
CS360 Windows Programming
Introduction Enosis Learning.
CSC 253 Lecture 8.
Realizing Concurrency using Posix Threads (pthreads)
CSC 253 Lecture 8.
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Scope, Visibility, and Lifetime
Process Tables; Threads
Multithreading Tutorial
Object-Oriented Software Engineering
Multithreading Tutorial
CSCI1600: Embedded and Real Time Software
Multithreading Tutorial
Java History, Editions, Version Features
Realizing Concurrency using Posix Threads (pthreads)
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
Dynamic Memory.
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSCI1600: Embedded and Real Time Software
Object Oriented Programming (OOP) Lecture No. 11
Threads CSE 2431: Introduction to Operating Systems
CS Introduction to Operating Systems
Presentation transcript:

SB Implementing ScriptBasic Multi- Thread How to embed ScriptBasic multi-thread?

SB Contents Who this presentation is for What is multi-thread, issues 2 ways of mt ScriptBasic Issues when implementing dependent threads Solutions for the issues

SB Who this presentation is for Curious (why things happen?) Want to learn and understand how ScriptBasic works Want to embed ScriptBasic into multi threaded application NOT for those, who just want to program in scriba

SB What is multi-thread? A single process runs several threads simultaneous A thread has its own stack and call sequence Threads share memory and other process resources UNIX thread is just a process w/o separate data

SB Issues regarding threads Don’t use global variables (except for constant values, like ScriptBasic syntax definition tables) Carefully design locking mechanisms Free memory yourself, don’t rely on OS

SB Enabling MT ScriptBasic No global variables No memory leaking Object oriented approach (although it is C and not C++) Thread and lock primitives for portability ( thread.c )

SB Two way of MT embedding Independent threads (ex: Eszter SB Engine v1.0b22) Dependent threads, long-life worker threads (ex: Eszter SB Engine v1.0b23)

SB Independent threads Threads run independent of each other Possibility and advised to share configuration file Possibility and advised to cache program code in memory (though even v1.0b22 does not) Can’t and should not share support function table

SB Dependent threads Threads access shared data Example: –session handling in web server –Long-life application „global” variables –Locks (not flock, but memory mutexes)

SB Pseudo Interpreter (config, global ST) Thread life-time and ST object life time PROCESS Basic thread Module worker thread Basic thread ST

SB Initializing and using global ST InitModuleInterface –Initializes the module Support Function Table InheritModuleInterface –Sets the Support Function Inherit pointer but has NO effect on the object Support Function Table

SB Module worker thread Module life-time PROCESS Basic thread Module instance counter 2 PROCESS

SB Worker thread initialization DllMain (W32) or _init (UNIX) has no ST bootmodu is called for each thread Solution: use bootmodu with the help of –basext.h macros –Process level global variables

SB MT special macros and variables #define SUPPORT_MULTITHREAD \ static MUTEX mxThreadCounter,mxInit;\ static int iFirst;\ static long lThreadCounter; static void *pProcessLevelMemorySegment;

SB Initialization code in bootmodu INC_THREAD_COUNTER INITLOCK if( iFirst ){ /* inherit malloc and free from pMemorySegment */ pProcessLevelMemorySegment = besINIT_SEGMENT(pSt->pEo->pMemorySegment,NULL); besCreateThread(&hT,worker_thread, pSt->pEo->pSTI); iFirst = 0 } INITUNLO /* unlock the init mutex */

SB New control function besSUB_KEEP long lTC; GET_THREAD_COUNTER(lTC); if( lTC == 0 ){ INC_THREAD_COUNTER } return lTC ? 1 : 0; besEND

SB Module worker thread Module life-time using besSUB_KEEP PROCESS Basic thread Module instance counter 2 PROCESS

SB Thank you for your attention