반응형
현재 메서드 호출의 스레드 ID를 가져오는 중
현재 메서드가 실행 중인 현재 스레드 ID를 출력할 수 있는 방법이 있습니까?
(209-c로 부탁합니다)
NSLog(@"%@", [NSThread currentThread]);
인 스위프트 5
print("Current thread \(Thread.current)")
#include <pthread.h>
...
mach_port_t machTID = pthread_mach_thread_np(pthread_self());
NSLog(@"current thread: %x", machTID);
인 스위프트
print("Current thread \(NSThread.currentThread())")
인 스위프트4
print("\(Thread.current)")
다음과 같은 것을 해킹할 수 있습니다(이것은 단지 예쁘게 인쇄되지만, 번호를 얻을 때까지 계속해서 나눌 수 있습니다).
+ (NSString *)getPrettyCurrentThreadDescription {
NSString *raw = [NSString stringWithFormat:@"%@", [NSThread currentThread]];
NSArray *firstSplit = [raw componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"{"]];
if ([firstSplit count] > 1) {
NSArray *secondSplit = [firstSplit[1] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"}"]];
if ([secondSplit count] > 0) {
NSString *numberAndName = secondSplit[0];
return numberAndName;
}
}
return raw;
}
NSLog
호출된 스레드를 식별하는 숫자(콜론 뒤의 대괄호로 표시)를 콘솔에 인쇄합니다.
unint64_ttid; pthread_threadid_np(NULL, &tid);
언급URL : https://stackoverflow.com/questions/1616572/getting-thread-id-of-current-method-call
반응형
'it-source' 카테고리의 다른 글
wpf 데이터 그리드 및 추가 UI 요소가 있는 스크롤 뷰어에서 마우스 스크롤이 작동하지 않음 (0) | 2023.05.21 |
---|---|
값이 null이 아닌 데이터 트리거? (0) | 2023.05.21 |
jQuery를 사용하여 요소의 제목 속성을 변경하는 방법 (0) | 2023.05.16 |
MVVM 모델에서 모델은 INOTIFY를 구현해야 합니다.속성 변경된 인터페이스? (0) | 2023.05.16 |
우리는 언제 조개 변수 주변에 곱슬곱슬한 중괄호가 필요합니까? (0) | 2023.05.16 |