happyj2me
3/13/2019 - 10:37 AM

vscode-config

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Library/Developer/CommandLineTools/usr/include/c++/v1",
                "/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0/include",
                "/Library/Developer/CommandLineTools/usr/include",
                "/usr/include",
                "/usr/local/include",
                
                "/usr/local/Cellar/glib/2.60.0/include/glib-2.0",
                "/usr/local/Cellar/glib/2.60.0/lib/glib-2.0/include",
                "/usr/local/opt/gettext/include",
                "/usr/local/Cellar/pcre/8.43/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "c/c++ Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "lldb",
            "preLaunchTask":"c++"
        },
    ]
}

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "c++",
            "command": "g++",
            "type": "shell",
            "args": [
                "thread.cpp",                     //当前文件名
                "-std=c++11",
                "-g",
                "-o",                            //对象名,不进行编译优化
                "${workspaceFolder}/a.out",  //当前文件名(去掉扩展名)
                "`pkg-config", "--libs", "--cflags", "glib-2.0`",
            ],
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            }
        }
    ]
}

#include <glib.h>
#include <glib/gprintf.h>
#include <unistd.h>
#include <errno.h>

#include "sys/select.h"
#include "sys/time.h"

gint64 janus_get_monotonic_time() {
	struct timespec ts;
	clock_gettime (CLOCK_MONOTONIC, &ts);
	return (ts.tv_sec*G_GINT64_CONSTANT(1000000)) + (ts.tv_nsec/G_GINT64_CONSTANT(1000));
}
gpointer thread_proc_1(gpointer data)
{
    struct timeval tv;
    int err = 0;
    int i = 0;
    do
    {
        tv.tv_sec = 6;
        tv.tv_usec = 0;
        err = select(0, NULL, NULL, NULL, &tv);
    } while (err == 0 || errno == EINTR);
    g_printf("err = %d\n",err);
    return 0;
}
int main(int argc, char *argv[])
{
    gint64 start = janus_get_monotonic_time();
    GError *error;
    GThread *t1 = g_thread_try_new("gthread_1", thread_proc_1, NULL, &error);
    g_thread_join(t1);
    gint64 end = janus_get_monotonic_time();
    g_printf("run time:%lld\n",end-start);
    return 0;
}