【问题标题】:Can't create thread in vala: `GLib.Thread' does not have a default constructor无法在 vala 中创建线程:`GLib.Thread' 没有默认构造函数
【发布时间】:2014-11-11 14:06:52
【问题描述】:

此示例程序无法编译:

public class MyClass 
{
    public bool do_work () {
       message ("OTHER THREAD: %p", (void*)Thread.self ) ;
       return false ;
    }

    public void run () {
        Thread<bool> thread1 = new Thread<bool>.try ("queuejobmanager-thread-1", do_work);
        thread1.join () ;
    }
 }       

int main (string[] args) {

    message ("MAIN THREAD: %p", (void*)Thread.self ) ;
    var item = new MyClass () ;
    item.run () ;
    return 0 ;
}

错误是:

vala-thread.vala:10.36-10.51: error: The name `try' does not exist in the context of `GLib.Thread'
        Thread<bool> thread1 = new Thread<bool>.try ("queuejobmanager-thread-1", do_work);

【问题讨论】:

    标签: multithreading glib vala


    【解决方案1】:

    the sample 中所述,您必须使用选项--target-glib 2.32

    进行构建

    完整的构建行是:

    valac <your vala file>  --target-glib 2.32 
    

    【讨论】:

      【解决方案2】:

      这是一个可以自定义的填充

      VALAC=valac
      EXEC=runMe
      VALAFILES=test.vala test2.vala test3.vala
      VALAPKGS=
      VALAOPTS=--thread --target-glib=2.32
      
      default:
          $(VALAC) $(VALAFILES) -o $(EXEC) $(VALAPKGS) $(VALAOPTS)
      
      run:
          ./$(EXEC)
      
      clean:
          rm -f *.o pp
      

      在该行中输入您要编译的类

      VALA 文件 = test.vala

      然后在bash中执行命令;

      制作

      运行

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-15
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        • 2012-11-03
        • 2016-07-18
        • 2021-09-04
        • 2017-08-30
        相关资源
        最近更新 更多