発明の巻

Similar documents
file:///D|/C言語の擬似クラス.txt

タイトル (title): C 言語の疑似スレッド サブタイトル (subtitle): C 言語の偽物のスレッド The thread at the imitation of the C language. 似ているが独創的な別物 The resembling but original singl

memo

I117 7 School of Information Science, Japan Advanced Institute of Science and Technology

解きながら学ぶC++入門編

Taro-リストⅠ(公開版).jtd

Microsoft Word - no15.docx

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

PowerPoint プレゼンテーション

バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション

Microsoft Word - no206.docx

Microsoft Word - no12.doc

Microsoft Word - Cプログラミング演習(12)

memo

Microsoft Word - Training10_プリプロセッサ.docx

Microsoft PowerPoint - kougi9.ppt

char int float double の変数型はそれぞれ 文字あるいは小さな整数 整数 実数 より精度の高い ( 数値のより大きい より小さい ) 実数 を扱う時に用いる 備考 : 基本型の説明に示した 浮動小数点 とは数値を指数表現で表す方法である 例えば は指数表現で 3 書く

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション

Taro-リストⅢ(公開版).jtd

Microsoft PowerPoint - CproNt02.ppt [互換モード]

関数の動作 / printhw(); 7 printf(" n"); printhw(); printf("############ n"); 4 printhw(); 5 関数の作り方 ( 関数名 ) 戻り値 ( 後述 ) void である. 関数名 (

C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf ("sum=%d n",sum); 2

Undestand の解析 Understand の C 言語で抽出できない依存関係について サンプルコードを用いて説明します 確認バージョン Understand 3.0 (Build 640) Understand 3.1 (Build 700) Understand 4.0 (Build 78

< F2D F B834E2E6A7464>

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

r08.dvi

Prog1_15th

Microsoft PowerPoint - 14Chap17.ppt

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

プログラミング方法論 II 第 14,15 回 ( 担当 : 鈴木伸夫 ) 問題 17. x 座標と y 座標をメンバに持つ構造体 Point を作成せよ 但し座標 は double 型とする typedef struct{ (a) x; (b) y; } Point; 問題 18. 問題 17 の

数はファイル内のどの関数からでも参照できるので便利ではありますが 変数の衝突が起こったり ファイル内のどこで値が書き換えられたかわかりづらくなったりなどの欠点があります 複数の関数で変数を共有する時は出来るだけ引数を使うようにし グローバル変数は プログラムの全体の状態を表すものなど最低限のものに留

‚æ4›ñ

第3回 配列とリスト

講習No.12

PowerPoint Presentation

kiso2-09.key

Microsoft Word - no11.docx

PowerPoint プレゼンテーション

第3回 配列とリスト

< F2D B838A835882CC8CF68EAE2E6A7464>

ohp08.dvi

た場合クラスを用いて 以下のように書くことが出来る ( 教科書 p.270) プログラム例 2( ソースファイル名 :Chap08/AccountTester.java) // 銀行口座クラスとそれをテストするクラス第 1 版 // 銀行口座クラス class Account String name

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード]

Microsoft PowerPoint ppt

ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする ) ためには 同期処理を用いるこ とが必要になる 同期処理は 予約語 synchronized で行うことができる ここでは sy

Microsoft Word - no02.doc

教材ドットコムオリジナル教材 0から始めるiアフ リ リファレンス i アプリ簡易リファレンス ver i アプリ Java 独自のメソッド (1)iアプリの命令を使えるようにする import com.nttdocomo.ui.*; (2) 乱数を使う import java.u

RTC_STM32F4 の説明 2013/10/20 STM32F4 内蔵 RTC の日付 時刻の設定および読み込みを行うプログラムです UART2( 非同期シリアル通信ポート 2) を使用して RTC の設定および読み込みを行います 無料の開発ツール Atollic TrueSTUDIO for

:30 12:00 I. I VI II. III. IV. a d V. VI

C C UNIX C ( ) 4 1 HTML 1

program7app.ppt

‚æ2›ñ C„¾„ê‡Ìš|

プログラミングI第10回

Microsoft PowerPoint Java基本技術PrintOut.ppt [互換モード]

第2回

< F2D82B682E182F182AF82F12E6A7464>

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

プログラミング及び演習 第1回 講義概容・実行制御

r07.dvi

8 / 0 1 i++ i 1 i-- i C !!! C 2

< F2D825282CC947B909482CC A815B83682E6A>

ohp07.dvi

問題1 以下に示すプログラムは、次の処理をするプログラムである

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

< F2D834F838C A815B A CC>

Microsoft Word - Cプログラミング演習(10)

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

第 2 章インタフェース定義言語 (IDL) IDL とは 言語や OS に依存しないインタフェース定義を行うためのインタフェース定義言語です CORBA アプリケーションを作成する場合は インタフェースを定義した IDL ファイルを作成する必要があります ここでは IDL の文法や IDL ファイ

C 言語の式と文 C 言語の文 ( 関数の呼び出し ) printf("hello, n"); 式 a a+4 a++ a = 7 関数名関数の引数セミコロン 3 < a "hello" printf("hello") 関数の引数は () で囲み, 中に式を書く. 文 ( 式文 ) は

プログラミング基礎

JVMTIを使った超低負荷プロファイラの作成

Microsoft PowerPoint - 計算機言語 第7回.ppt

XMPによる並列化実装2

Prog2_12th

:30 12:00 I. I VI II. III. IV. a d V. VI


Microsoft PowerPoint - 15Game.ppt

二分木の実装

演習課題No12

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdiu.h> #define InFile "data.txt" #define OutFile "surted.txt" #def

double float

C 言語第 3 回 2 a と b? 関係演算子 a と b の関係 関係演算子 等しい a==b 等しくない a!=b より大きい a>b 以上 a>=b より小さい a<b 以下 a<=b 状態 真偽 値 条件が満たされた場合 TRUE( 真 ) 1(0 以外 ) 条件が満たされなかった場合 F

< F2D92DE82E8914B82CC977088D32E6A7464>

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

PowerPoint プレゼンテーション

第1回 プログラミング演習3 センサーアプリケーション

untitled

ポインタ変数

Taro-再帰関数Ⅱ(公開版).jtd

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdio.h> #define InFile "data.txt" #define OutFile "sorted.txt" #def

プログラミング基礎

02: 変数と標準入出力

< F2D8EA CE909482CC92EA82852E6A7464>

untitled

untitled

Transcription:

発明の巻

スレッドとは コンピュータープログラミング上の 並列処理の機能です スレッドをサポートしているプログラミング言語と スレッドをサポートしていないプログラミング言語があります 高度な機能のスレッドをわざとサポートしない言語があるのは パソコン以外の環境で実行するために 低レベルマイコン対応のプログラミング言語でいるから ( 例えば C 言語 ) です 代わりにマイコンにはインターバルタイマーがあります ただし C 言語からインターバルタイマーを使用するには そのマイコンのマニュアルだけではなく そのマイコンの C 言語のマニュアルも必要です H 社さんの社員さんは H 社さんの製品のマイコンのインターバルタイマーを呼び出せるでしょう H 社さんの社員さん以外の方は 情報を揃えるのが困難なので H 社さんの製品のマイコンのインターバルタイマーを呼び出すのは困難でしょう

M 社さんの社員さんは M 社さんの製品のマイコンのインターバルタイマーを呼び出せるでしょう M 社さんの社員さん以外の方は 情報を揃えるのが困難なので M 社さんの製品のマイコンのインターバルタイマーを呼び出すのは困難でしょう したがって 大手の社員さんは その大手の会社の製品のマイコンのインターバルタイマーを呼び出せるでしょう 一般の方は 情報を揃えるのが困難なので マイコンのインターバルタイマーを呼び出すのは困難でしょう 今回作成しました 並行処理タイプのスレッド ( 疑似スレッドと命名 ) は インターバルタイマーの使い方が習得できない一般の方には 朗報かも知れません

発明アルゴリズムに疑似スレッドと名付けました 本物に偽物と名付けました 特許申請はしないで 無料公開をいたしました 発明という手段で人類としてのノルマを達成し また 生きた証が発生いたしました 篠宮氏を逆賊に祭り上げようとする人種がいます 篠宮氏は辞退いたします 秋篠宮家様は本物の皇族ですが 篠宮氏は偽物です

タイトル (title): C 言語の疑似スレッド サブタイトル (subtitle): C 言語の偽物のスレッド The thread at the imitation of the C language. 似ているが独創的な別物 The resembling but original singleton. C 言語によるスレッドという概念の模倣 Copying a concept, the thread, by the C language.

/* C.h */ #include <stdio.h> /* printf() */ #include <time.h> /* time(), clock() */ #include <stdlib.h> /* calloc(), free(), rand() */ #include <conio.h> /* kbhit(), getche() */ #define CLEAR system("cls") #define OK 1 #define NG 0 #define USE_THREAD #define SLEEP_PER_SEC 100000000.0 file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/C.h.txt[16/04/06 ( ) 20:41:02]

/* Timer.h */ /* 時間に使用する定数の宣言 */ #define WOVICLOCKSIZE 1000000.0 /* 疑似スレッド定義 */ #ifdef USE_THREAD /* 疑似スレッドに使用する定数の宣言 */ #define INITCLOCKNO 1000001 #define STOPCLOCKNO 1000002 /* 構造体宣言 */ typedef struct tag_thread /* 疑似スレッドID */ int ID; /* 指定開始時 */ double preclock; /* woviclockがpreclockからsetclock 秒増えたらRunを呼ぶ */ double setclock; /* Runが呼ばれた回数を調べるために使用 (countupnextrunが呼ばれた回数) */ long count; /* List 機能 */ struct tag_thread *previous; struct tag_thread *next; Thread; file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.h.txt[16/04/06 ( 水 ) 20:42:00]

/* 疑似メソッドとwovi 用関数のプロトタイプ宣言 */ /* 宣言の順番は以下の通り */ #endif double getclock(void); #ifdef USE_THREAD void nextrun(thread *This, unsigned int ms); void countupnextrun(thread *This, unsigned int ms); void Run(Thread *This); /* main.cで内容を定義します */ void Init(Thread *This); /* main.cで内容を定義します */ void Destroy(Thread *This); /* main.cで内容を定義します */ Thread *new_thread(unsigned short int id); void delete_(thread *This); void Start(Thread *This); void Stop(Thread *This); int Thread_checkAllDelete(void); Thread *Thread_getThread(unsigned short int id); Thread *Thread_Start(unsigned short int id); void Thread_Toggle(unsigned short int id); void wovirun(void); void woviinit(void); /* タイマ関数 */ void wovi(double threadpersec); /* タイマ初期化関数 */ void initwovi(void); #endif /* ミリ秒待ち関数 */ void SleepMSec(double sleeppersec, unsigned int ms); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.h.txt[16/04/06 ( 水 ) 20:42:00]

/* ミリ秒待ち関数 */ void setsleep(unsigned int ms); /* 現在日時表示 */ void PrintCurrentTime(void); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.h.txt[16/04/06 ( 水 ) 20:42:00]

/* Timer.c */ #include "C.h" #include "Timer.h" /* 時間を表す外部変数宣言 */ double woviclock; /* 疑似スレッド定義 */ #ifdef USE_THREAD /* wovi 用疑似インスタンス宣言 */ Thread wovithreadfirst; Thread wovithreadlast; #endif /* 時刻取得 */ double getclock(void) return woviclock; #ifdef USE_THREAD /* スレッドの void Sleep(int ms) の代用 */ void nextrun(thread *This, unsigned int ms) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

This->preClock = woviclock; This->setClock = (((double) ms) / 1000); return; /* スレッドのvoid Sleep(int ms) の代用 */ void countupnextrun(thread *This, unsigned int ms) nextrun(this, ms); This->count++; /* スレッドのコンストラクタの代用 */ Thread *new_thread(unsigned short int id) Thread *List; Thread *new_list; List = &wovithreadfirst; while(list->next->next!= NULL) List = List->next; new_list = (Thread *)calloc(1, sizeof(thread)); if(new_list == NULL) printf("\ncalloc failed"); return NULL; new_list->previous = List; file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

new_list->next = List->next; new_list->next->previous = new_list; List->next = new_list; new_list->preclock = INITCLOCKNO; new_list->setclock = 0; new_list->id = id; new_list->count = 0; /* スレッドのvoid init(void) の代用 */ Init(new_List); return new_list; /* スレッドのデストラクタの代用 */ void delete_(thread *This) Destroy(This); This->previous->next = This->next; This->next->previous = This->previous; free(this); return; /* スレッドのvoid start(void) の代用 */ void Start(Thread *This) woviclock = getclock(); This->preClock = woviclock; return; file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

/* スレッドのvoid stop(void) の代用 */ void Stop(Thread *This) This->preClock = STOPCLOCKNO; return; int Thread_checkAllDelete(void) if(wovithreadfirst.next->next == NULL) return OK; else return NG; Thread *Thread_getThread(unsigned short int id) Thread *th; if(wovithreadfirst.next->next == NULL) return NULL; else file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

th = wovithreadfirst.next; do if(th->id == id) return th; else th = th->next; while(th->next!= NULL); return NULL; Thread *Thread_Start(unsigned short int id) Thread *th; th = Thread_getThread(id); if(th == NULL) th = new_thread(id); Start(th); else if(th->preclock == STOPCLOCKNO) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

Start(th); return th; void Thread_Toggle(unsigned short int id) Thread *th; th = Thread_getThread(id); if(th == NULL) th = new_thread(id); Start(th); else if(th->preclock == STOPCLOCKNO) Start(th); else delete_(th); return; /* Run を呼ぶタイミング */ void wovirun(void) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

double woviclockcompare; Thread *List; Thread *next_list; List = &wovithreadfirst; List = List->next; while(list->next!= NULL) next_list = List->next; if((list->preclock!= INITCLOCKNO) && (List->preClock!= STOPCLOCKNO)) woviclockcompare = List->preClock + List->setClock; if(woviclock < List->preClock) woviclockcompare -= WOVICLOCKSIZE; if(woviclock >= woviclockcompare) List->preClock = woviclock; /* スレッドのvoid run(void) の代用 */ Run(List); List = next_list; return; /* 指定開始時 OFF */ file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

void woviinit(void) wovithreadfirst.previous = NULL; wovithreadfirst.next = &wovithreadlast; wovithreadlast.previous = &wovithreadfirst; wovithreadlast.next = NULL; return; /* タイマ関数 */ void wovi(double threadpersec) woviclock += 1.0 / threadpersec; if(woviclock >= WOVICLOCKSIZE) printf("\noverwovi"); woviclock -= WOVICLOCKSIZE; wovirun(); /* スレッドのためのRunを呼ぶタイミング */ return; /* タイマ初期化関数 */ void initwovi(void) woviclock = 0.0; woviinit(); /* スレッドのための指定開始時 OFF */ return; file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

#endif /* ミリ秒待ち関数 */ void SleepMSec(double sleeppersec, unsigned int ms) double cnt; double set; cnt = 0.0; set = ((double) ms) / 1000; while(cnt < set) cnt += 1.0 / sleeppersec; return; /* ミリ秒待ち関数 */ void setsleep(unsigned int ms) double start; double set; double end; start = clock() / CLOCKS_PER_SEC; set = ((double) ms) / 1000; end = start; while(end < start + set) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

end = clock() / CLOCKS_PER_SEC; return; /* 現在日時表示 */ void PrintCurrentTime(void) time_t timer; struct tm *t_st; /* 現在時刻の取得 */ time(&timer); /* 現在時刻を構造体に変換 */ t_st = localtime(&timer); printf("%d",t_st->tm_year+1900); if(t_st->tm_mon+1 < 10) printf("0%d",t_st->tm_mon+1); else printf("%d",t_st->tm_mon+1); if(t_st->tm_mday < 10) printf("0%d",t_st->tm_mday); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

else printf("%d",t_st->tm_mday); printf(" "); if(t_st->tm_hour < 10) printf("0%d",t_st->tm_hour); else printf("%d",t_st->tm_hour); if(t_st->tm_min < 10) printf("0%d",t_st->tm_min); else printf("%d",t_st->tm_min); if(t_st->tm_sec < 10) printf("0%d",t_st->tm_sec); else printf("%d",t_st->tm_sec); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

return; file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/Timer.c.txt[2016/11/20 22:06:26]

/* main.h */ #ifndef Timer_h #define Timer_h #include "Timer.h" #endif #define COURSESIZE 8 #define THREADSIZE 4 file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.h.txt[16/04/06 ( ) 20:43:03]

/* main.c */ #include "C.h" #include "main.h" #ifdef USE_THREAD struct Count int cnt[coursesize]; ; struct Count Cnt; void Thread0(void) int i,j; int i_cnt, j_cnt; /* 擬似スレッドの擬似インスタンス宣言 */ Thread* th[coursesize]; printf("\nthread Ready GO! で開始して競馬のコースが8コースありますが "); printf("\n<1> コースは 'r' ボタンが鞭で <2> コースは 'l' ボタンが鞭です "); printf("\nゴールまで80 歩です "); /* 擬似スレッドの擬似インスタンス初期化 */ for(i = 0; i < COURSESIZE; i++) th[i] = new_thread(i + 1); /* 5 秒待機 */ SleepMSec(SLEEP_PER_SEC, 5000); /* 擬似スレッド開始 */ file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

printf("\nthread Ready GO!\n"); /* 2 秒待機 */ SleepMSec(SLEEP_PER_SEC, 2000); for(i = 0; i < COURSESIZE; i++) Start(th[i]); for(;;) /* タイマー呼び出し */ wovi(5000000.0); i_cnt = Cnt.cnt[0]; j_cnt = 0; for(i = 1; i < COURSESIZE; i++) if(i_cnt < Cnt.cnt[i]) i_cnt = Cnt.cnt[i]; j_cnt = i; if(i_cnt >= 77) break; CLEAR; printf("goal!\n<%d>won", (j_cnt + 1)); for(i = 0; i < COURSESIZE; i++) delete_(th[i]); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

/* 5 秒待機 */ SleepMSec(SLEEP_PER_SEC, 5000); return; void Thread1(void) unsigned short int i; /* 疑似スレッドの疑似インスタンス宣言 */ Thread *th[threadsize]; printf("\ncountup"); /* 疑似スレッドの疑似インスタンス初期化 */ for(i = 0; i < THREADSIZE; i++) th[i] = new_thread(i + 11); /* 2 秒待機 */ SleepMSec(SLEEP_PER_SEC, 2000); /* 疑似スレッド開始 */ printf("\nstart"); for(i = 0; i < THREADSIZE; i++) Start(th[i]); for(;;) /* タイマー呼び出し */ wovi(25000000.0); if(thread_checkalldelete() == OK) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

break; return; void Thread2(void) Thread *th19; Thread *th20; th19 = new_thread(19); Start(th19); th20 = new_thread(20); Start(th20); for(;;) /* タイマー呼び出し */ wovi(5000000.0); if((th19->previous->previous == NULL) && (th19->next->next == NULL)) delete_(th19); break; return; file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

#endif void main(void) printf("\nhello BCC"); #ifdef USE_THREAD /* タイマー初期化 */ initwovi(); /* 第 1 部分 */ Thread0(); #endif printf("\nnext"); /* 2 秒待機 */ SleepMSec(SLEEP_PER_SEC, 2000); #ifdef USE_THREAD /* 第 2 部分 */ Thread1(); #endif printf("\nnext"); /* 2 秒待機 */ SleepMSec(SLEEP_PER_SEC, 2000); #ifdef USE_THREAD /* 第 3 部分 */ Thread2(); #endif printf("\nend"); /* 10 秒待機 */ file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

SleepMSec(SLEEP_PER_SEC, 10000); return; #ifdef USE_THREAD /* * 擬似スレッドの擬似メソッド関数 */ /* public void paint(graphics g) の代用 */ void Repaint(void) int i,j; CLEAR; for(i = 0; i < COURSESIZE; i++) for(j = 0; j < Cnt.cnt[i]; j++) printf(" "); printf("<%d>", (i + 1)); printf("\n"); return; /* * 疑似スレッドの疑似メソッド関数 */ /* スレッドのpublic void run() の代用 */ void Run(Thread *This) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

Thread *th11; int i; char key = ' '; if(this->id == 1) Repaint(); if(kbhit()) key = getche(); if(key == 'r') Cnt.cnt[0]++; nextrun(this, (((rand() % 9) + 10) * 30)); while(kbhit()) key = getche(); if(key == NULL) break; else if(this->id == 2) Repaint(); if(kbhit()) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

key = getche(); if(key == 'l') Cnt.cnt[1]++; nextrun(this, (((rand() % 9) + 10) * 30)); while(kbhit()) key = getche(); if(key == NULL) break; else if(((this->id) >= 3) && ((This->ID) <= COURSESIZE)) Repaint(); Cnt.cnt[(This->ID) - 1]++; nextrun(this, (((rand() % 9) + 10) * 200)); else if(this->id == 11) if(this->count == 1) printf("\n<11>1 回目 Time = "); PrintCurrentTime(); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

countupnextrun(this, (((rand() % 9) + 10) * 10 * 1)); else if(this->count == 2) printf("\n<11>2 回目 "); printf(" <11>Stop Time = "); PrintCurrentTime(); Stop(This); else if(this->count == 3) printf("\n<11>3 回目 Time = "); PrintCurrentTime(); countupnextrun(this, (((rand() % 9) + 10) * 10 * 1)); else if(this->count == 4) printf("\n<11>stop Time = "); PrintCurrentTime(); Stop(This); else if(this->id == 14) if(this->count == 1) printf("\n<14>1 回目 Time = "); PrintCurrentTime(); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

countupnextrun(this, (((rand() % 9) + 10) * 40 * 4)); else if(this->count == 2) printf("\n<14>2 回目 "); countupnextrun(this, (((rand() % 9) + 10) * 40 * 4)); printf(" <11>Start Time = "); PrintCurrentTime(); th11 = Thread_Start(11); countupnextrun(th11, (((rand() % 9) + 10) * 10 * 1)); else if(this->count == 3) printf("\n<14>3 回目 Time = "); PrintCurrentTime(); countupnextrun(this, (((rand() % 9) + 10) * 40 * 4)); else if(this->count == 4) th11 = Thread_getThread(11); if(th11!= NULL) delete_(th11); printf(" <14>Stop"); Stop(This); delete_(this); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

else if((this->id == 12) (This->ID == 13)) if(this->count <= 3) printf("\n<%d>%d 回目 Time = ", This->ID, This->count); PrintCurrentTime(); countupnextrun(this, (((rand() % 9) + 10) * 30 * ((This->ID) - 10))); else printf("\n<%d>stop", This->ID); Stop(This); delete_(this); else if(this->id == 19) key = ' '; nextrun(this, 1); if(kbhit()) key = getche(); if(key == '1') Thread_Toggle(21); file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

nextrun(this, 1000); else if(key == '2') Thread_Toggle(22); nextrun(this, 1000); else if(key == '3') Thread_Toggle(23); nextrun(this, 1000); else if(key == '4') Thread_Toggle(24); nextrun(this, 1000); else if(key == '5') Thread_Toggle(25); nextrun(this, 1000); else if(key == '6') Thread_Toggle(26); nextrun(this, 1000); else if(key == '7') file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

Thread_Toggle(27); nextrun(this, 1000); else if(key == '8') Thread_Toggle(28); nextrun(this, 1000); else if(key == '9') Thread_Toggle(29); nextrun(this, 1000); else if(key == '0') Thread_Toggle(20); nextrun(this, 1000); else printf("<%d>", This->ID); nextrun(this,2000); return; /* スレッドのコンストラクタの public void init() の代用 */ file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

void Init(Thread *This) int i; if(this->id == 1) Cnt.cnt[0] = 0; nextrun(this, (((rand() % 9) + 10) * 30)); else if(this->id == 2) Cnt.cnt[1] = 0; nextrun(this, (((rand() % 9) + 10) * 30)); else if((this->id >= 3) && (This->ID <= COURSESIZE)) Cnt.cnt[(This->ID) - 1] = 0; nextrun(this, (((rand() % 9) + 10) * 200)); else if((this->id >= 11) && (This->ID <= 14)) printf("\n<%d>init", This->ID); countupnextrun(this, (((rand() % 9) + 10) * 30 * ((This->ID) - 10))); else if((this->id >= 20) && (This->ID <= 29)) printf("\n<%d>init\n", This->ID); nextrun(this,2000); return; file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

/* スレッドのデストラクタの代用 */ void Destroy(Thread *This) if(this->id == 11) printf("\n<11>destroy"); else if((this->id == 12) (This->ID == 13) (This->ID == 14)) printf(" <%d>destroy Time = ", (This->ID)); PrintCurrentTime(); else if((this->id >= 20) && (This->ID <= 29)) printf("\n<%d>destroy\n", This->ID); return; #endif file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/main.c.txt[2016/11/20 19:18:02]

# makefile.mak CC = bcc32 main.exe : Timer.obj main.obj $(CC) main.obj Timer.obj Timer.obj : Timer.c Timer.h C.h $(CC) -c Timer.c main.obj : main.c main.h Timer.h C.h $(CC) -c main.c clean: del *.obj del *.tds file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/makefile.mak.txt[16/07/31 ( ) 16:07:13]

@rem build.bat C: set path=c:\borland\bcc55\bin;%path% D: cd D:\Hidemine_Shinomiya\C_Jockey\Jockey_Work del error.txt make -f makefile.mak >> error.txt make -f makefile.mak clean >> error.txt error.txt exit file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/build.bat.txt[16/04/06 ( ) 20:44:19]

MAKE Version 5.2 Copyright (c) 1987, 2000 Borland bcc32 -c Timer.c Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland Timer.c: bcc32 -c main.c Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland main.c: bcc32 main.obj Timer.obj Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland MAKE Version 5.2 Copyright (c) 1987, 2000 Borland del *.obj del *.tds file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_Work/error.txt[2016/11/20 22:07:29]

C 言語のプロジェクト Jockey について main.c の関数 Thread0 を見てください Thread Ready GO! で開始して競馬のコースが 8 コースありますが <1> コースは 'r' ボタンが鞭で <2> コースは 'l' ボタンが鞭です ゴールまで 80 歩です main.c の関数 Thread1 を見てください スレッドを使用しています Thread *th[threadsize]; でオブジェクト宣言しています th[i] = new_thread(i + 1); で初期値設定しています この2 行は Java で次と同じ意味です Thread th[] = new Thread[THREADSIZE]; th[i] = new Thread(i + 1); Start(th[i]); でスレッドを開始しています この 1 行は Java で次と同じ意味です th[i].start(); void Run(Thread *This)... void Init(Thread *This) file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_ReadMe.txt[16/07/31 ( 日 ) 16:27:37]

... はそれぞれ Java で次と同じ意味です public void run()... public void init()... delete_(this); でオブジェクトを消去しています この 1 行は C++ で次と同じ意味です delete this; main.c の関数 Thread2 を見てください スレッド20が走り始めたら 0 以外の数字キーを押してみてください その数字に20を加えた番号のスレッドが キーを押す度毎に 起動 消去を繰り返します 20を含めて 全部スレッドが消去されると 終了です これらのスレッドに関する仕様は Timer.c に記述しました file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_ReadMe.txt[16/07/31 ( 日 ) 16:27:37]

makefile.mak build.bat は複数のファイルを 1 個のプロジェクトとして コンパイルするためのファイルです file:///d /Hidemine_Shinomiya/C_Jockey/Jockey_ReadMe.txt[16/07/31 ( 日 ) 16:27:37]

著作者 : しのみやひでみね 篠宮 英峰