List
Add
Info
Contact
Stats
To edit this entry i need username and password!
Fields marked * are required!
* Username:
* Password:
Type:
Sourcecode (WITHOUT BBCode support)
Name:
ThreadCancel.bas
* Data:
(max. 1 MB)
Available TAG's (new window)
#IF defined(__fb_linux__) declare function pthread_cancel cdecl lib "c" alias "pthread_cancel" (byval pthread_t as integer) as integer #ELSEIF defined(__fb_win32__) #include once "windows.bi" #ENDIF Sub ThreadCancel(thread as Any Ptr) #IF defined(__fb_linux__) pthread_cancel(Cast(Integer Ptr, thread)[0]) #ELSEIF defined(__fb_win32__) TerminateThread(Cast(Handle Ptr, thread)[0], 0) #ENDIF End Sub sub threadtest() print "thread-running" Dim C as UInteger do print timer() sleep 500, 1 c += 1 If c = 10 then exit do loop print "thread-exiting loop exit" end sub print "init thread..." Dim tthread as any ptr = threadcreate(Cast(Any Ptr, @threadtest)) print "wait 2 secs" sleep 2000, 1 print "try cancle thread..." ThreadCancel(tthread) print "wait threadexit..." threadwait(tthread) print "thread exit success!" end 0
Filetype / Highlight:
freeBASIC
Action: