Code Monkey home page Code Monkey logo

go-pthreads's People

Contributors

liamzdenek avatar spikeekips avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-pthreads's Issues

go run error

root@controller1 xx # GOOS=linux go run a.go
go build github.com/liamzdenek/go-pthreads: build constraints exclude all Go files in /root/go/pkg/mod/github.com/liamzdenek/[email protected]

Possibly returning a function local variable address ?

I could be mistaken but I feel that func Create (), can return address of a local variable which gets destroyed after the end func Create(). At line 55 in func Create (), pidptr is defined to point to address of function local variable "pid" which stores the pthread_t returned by pthread_create() library call. pthread_create() requires the address of a variable (as is normal for all kernel calls) to return the pthread_t value.
Now, since we return the address of local variable "pid" after converting it to a unsafe.Pointer, the garbage collector of 'go' will not add an extra reference to the local variable "pid" and when we return the said value, it may get overwritten. Any subsequent attempt to kill the thread represented by 'Thread' may now work or may not depending on whether the local variable value was overwritten or otherwise.
It's probably best to ask the user to supply a type 'Thread' as an argument to func Create() and return the pid in the passed caller variable, than allocating one on stack of func Create(). Makes sense ?

This might also perhaps explain the error seen by kryptodev.

You can't, like, kill a thread

I am a bit concerned about the things you claim this library does. To be absolutely clear, there is no mechanism on any modern operating system to "kill" a thread. In fact, your library using pthread_kill to send itself a SIGSEGV (which is a segmentation fault, by the way) will probably kill something, but almost certainly not the thing you intend.

By the way, the only difference between pthread_kill and kill is that you can use the pthread_t thread id to specify which task gets the signal. By default, the signal still applies to the entire process. Doing what you're doing in a C program will promptly exit the entire process. In Go, it probably leads to undefined behavior.

This library is broken by design, and I promise you that it's not doing what you think it's doing.

thread.kill() gets stuck endlessly

Hello,

I hope I am not simply making a mistake but I have noticed that when I create a pthread inside a new goroutine(not the main), and I try to call thread.kill(), it does not always work. Sometimes I does, other times it just gets stuck.

It would be very kind of you to investigate this in your free time.

Thank you

Check whether long running thread code is finished or not, using `channel`.

(This is not bug report or enhancement :)

I tested for long running routine and found there is no way to check the thread is alive or not. Of course Thread.Running is available but it seems to be incomplete. This is simple method to check whether long running routine is finished or not, using channel.

_ch := make(chan bool)

thread := pthread.Create(func() {
    ... long running routine ...

    _ch <- true
})

<- _ch

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.