Windows編程
多線程編程:`/*
ThreadedClient.cpp
A threaded database client.
*/
#include
#include “servers.h”
#ifdef _MSC_VER
#include <windows.h>
#include <winbase.h>
#include <process.h>
typedef __int64 INT64_T;
typedef unsigned __int64 UINT64_T;
typedef LONGLONG time_ms_t;
time_ms_t getTimeInMilliseconds() {
SYSTEMTIME stime;
GetSystemTime( &stime );
FILETIME ftime;
LARGE_INTEGER time;
SystemTimeToFileTime( &stime, &ftime ); /* if this fails... */
time.HighPart = ftime.dwHighDateTime;
time.LowPart = ftime.dwLowDateTime;
/* FileTime is in 100ns intervals since 1/1/1601 */
return time.QuadPart / 10000;
}
#endif
/*
ostream &operator <<( ostream &out, string *str ) {
Send a string to an output stream.
*/
ostream &operator<<(ostream &out, string *str) {
if (str)
return out << str->data();
else
return out;
}
/*
ostream & operator<< ( ostream &out, INT64_T num )
Print a 64-bit unsigned integer to the given output stream.
*/
ostream &operator<<( ostream &out, INT64_T snum ) {
#define _OSTR_LL_LEN 21
if (snum) {
char buffer[_OSTR_LL_LEN];
int i = _OSTR_LL_LEN - 1;
UINT64_T num;
if (snum < 0) num = -snum; else num = snum;
buffer[i] = '\0';
while (num) {
buffer[--i] = ('0' + (int) (num % 10));
num /= 10;
}
if (snum < 0) buffer[--i] = '-';
return out << buffer + i;
}else return out << '0';
}
/*
int main( int argc, char *argv[]
You should modify this function to use threads.
*/
int account;
HANDLE handle2;
Personal *pers;
AccountInfo *acct;
long thread1;
long thread2;
void getname(void*pname){
pers=GetPersonalInformation( account );
_endthread();
}
void getaccount(void*pname){
acct=GetAccountInformation(account);
_endthread();
}
int main( int argc, char *argv[] ) {
if (argc != 2) {
cerr << “usage: " << argv[0] << " [account_number]” << endl;
exit(1);
}
int account = atoi( argv1 );
// int account=122;
time_ms_t start = getTimeInMilliseconds();
cout << “Retrieving…”;
cout.flush();
thread1=_beginthread(getname,0,NULL);
thread2=_beginthread(getaccount,0,NULL);
handle[0]=(void*)thread1;
handle[1]=(void*)thread2;
WaitForMultipleObjects(2,handle,false,INFINITE);
// Personal *pers = GetPersonalInformation( account );
// AccountInfo *acct = GetAccountInformation( account );
time_ms_t end = getTimeInMilliseconds();
cout << "done (" << end - start << "ms)" << endl;
if (pers) {
cout << account << ": " << pers->FirstName << " "
<< pers->LastName << endl;
cout << pers->Address << endl;
cout << "Balance: " << acct->Balance << ", " << acct->Pending
<< " pending, " << acct->Share << " share" << endl;
delete pers;
delete acct;
}else cout << "No client matches that account number" << endl;
return 0;
}`
全局變量是共享的,在主函數裏面創建的線程一般不需要返回值,直接賦值給全局變量就好
WaitForMultipleObjects(2,handle,false,INFINITE);第一個參數是HANDLE 數組中的個數,注意一定是數組;第二個是數組名,最後一個是等待的時間,可以理解爲等待線程執行完再繼續下一步的操作。
如果將子函數中的getname()和getaccount的返回值設置爲void*會報錯,並不清楚原因。
- 全新的界面設計 ,將會帶來全新的寫作體驗;
- 在創作中心設置你喜愛的代碼高亮樣式,Markdown 將代碼片顯示選擇的高亮樣式 進行展示;
- 增加了 圖片拖拽 功能,你可以將本地的圖片直接拖拽到編輯區域直接展示;
- 全新的 KaTeX數學公式 語法;
- 增加了支持甘特圖的mermaid語法1 功能;
- 增加了 多屏幕編輯 Markdown文章功能;
- 增加了 焦點寫作模式、預覽模式、簡潔寫作模式、左右區域同步滾輪設置 等功能,功能按鈕位於編輯區域與預覽區域中間;
- 增加了 檢查列表 功能。
功能快捷鍵
撤銷:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜體:Ctrl/Command + I
標題:Ctrl/Command + Shift + H
無序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
檢查列表:Ctrl/Command + Shift + C
插入代碼:Ctrl/Command + Shift + K
插入鏈接:Ctrl/Command + Shift + L
插入圖片:Ctrl/Command + Shift + G
查找:Ctrl/Command + F
替換:Ctrl/Command + G
合理的創建標題,有助於目錄的生成
直接輸入1次#,並按下space後,將生成1級標題。
輸入2次#,並按下space後,將生成2級標題。
以此類推,我們支持6級標題。有助於使用TOC
語法後生成一個完美的目錄。
如何改變文本的樣式
強調文本 強調文本
加粗文本 加粗文本
標記文本
刪除文本
引用文本
H2O is是液體。
210 運算結果是 1024.
插入鏈接與圖片
鏈接: link.
圖片:
帶尺寸的圖片:
居中的圖片:
居中並且帶尺寸的圖片:
當然,我們爲了讓用戶更加便捷,我們增加了圖片拖拽功能。
如何插入一段漂亮的代碼片
去博客設置頁面,選擇一款你喜歡的代碼片高亮樣式,下面展示同樣高亮的 代碼片
.
// An highlighted block
var foo = 'bar';
生成一個適合你的列表
- 項目
- 項目
- 項目
- 項目
- 項目1
- 項目2
- 項目3
- 計劃任務
- 完成任務
創建一個表格
一個簡單的表格是這麼創建的:
項目 | Value |
---|---|
電腦 | $1600 |
手機 | $12 |
導管 | $1 |
設定內容居中、居左、居右
使用:---------:
居中
使用:----------
居左
使用----------:
居右
第一列 | 第二列 | 第三列 |
---|---|---|
第一列文本居中 | 第二列文本居右 | 第三列文本居左 |
SmartyPants
SmartyPants將ASCII標點字符轉換爲“智能”印刷標點HTML實體。例如:
TYPE | ASCII | HTML |
---|---|---|
Single backticks | 'Isn't this fun?' |
‘Isn’t this fun?’ |
Quotes | "Isn't this fun?" |
“Isn’t this fun?” |
Dashes | -- is en-dash, --- is em-dash |
– is en-dash, — is em-dash |
創建一個自定義列表
- Markdown
- Text-to-HTML conversion tool
- Authors
- John
- Luke
如何創建一個註腳
一個具有註腳的文本。2
註釋也是必不可少的
Markdown將文本轉換爲 HTML。
KaTeX數學公式
您可以使用渲染LaTeX數學表達式 KaTeX:
Gamma公式展示 是通過歐拉積分
你可以找到更多關於的信息 LaTeX 數學表達式here.
新的甘特圖功能,豐富你的文章
- 關於 甘特圖 語法,參考 這兒,
UML 圖表
可以使用UML圖表進行渲染。 Mermaid. 例如下面產生的一個序列圖:
這將產生一個流程圖。:
- 關於 Mermaid 語法,參考 這兒,
FLowchart流程圖
我們依舊會支持flowchart的流程圖:
- 關於 Flowchart流程圖 語法,參考 這兒.
導出與導入
導出
如果你想嘗試使用此編輯器, 你可以在此篇文章任意編輯。當你完成了一篇文章的寫作, 在上方工具欄找到 文章導出 ,生成一個.md文件或者.html文件進行本地保存。
導入
如果你想加載一篇你寫過的.md文件,在上方工具欄可以選擇導入功能進行對應擴展名的文件導入,
繼續你的創作。
註腳的解釋 ↩︎