में एक हस्ताक्षरित int में एक पॉइंटर का पता संग्रहीत करना क्या एक हस्ताक्षर किए गए int पर पॉइंटर डालना संभव है, फिर बाद में इसे पॉइंटर पर डाला जाए? मैं पॉइंटर को एक pthread_t चर में एक स्ट्रक्चर में स्टोर करने की कोशिश कर रहा हूं, लेकिन मुझे इसे काम करने के लिए प्रतीत नहीं होता है। यहां मेरे कोड के कुछ स्निपेट हैं (मैं उपयोगकर्ता-स्तरीय थ्रेड प्रबंधन लाइब्रेरी बना रहा हूं)। जब मैं थ्रेड के टिप को मुद्रित करने का प्रयास करता हूं तो यह मुझे कुछ लंबा कचरा नंबर देता है।सी
संपादित करें: कोई बात नहीं, मुझे यह काम करने के लिए मिला।
मैं
thread = (pthread_t) currentThread;
बदल
को*thread = (pthread_t) currentThread;
लगा कि यह कुछ ऐसा है जो की तरह बेवकूफ था।
टेस्ट कार्यक्रम:
pthread_t thread1;
pthread_t thread2;
pthread_create(&thread1, NULL, runner, NULL);
pthread_create(&thread2, NULL, runner, NULL);
pthread_join(&thread2, NULL);
मेरी लायब्रेरी:
typedef struct queueItem
{
int tid;
ucontext_t context;
int caller;
struct queueItem *joiningOn;
struct queueItem *nextContext;
} queueItem;
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
{
thread = (pthread_t) currentThread;
}
...
int pthread_join(pthread_t thread, void **retval)
{
queueItem *t = (queueItem *) thread;
if(runningContext->joiningOn != NULL) // Current thread is already waiting on another
return EINVAL;
if(t == NULL) // If thread to join on is invalid
return 0;
fprintf(stdout, "JOINEE: %d\n", t->tid); // Prints weird number
runningContext->caller = JOIN;
runningContext->joiningOn = t;
swapcontext(&(runningContext->context), &scheduleContext);
}
मुझे समझ नहीं आता है - आप अपने पुस्तकालय में pthread_create परिभाषित किया है? उस नाम से सामान्य फ़ंक्शन के साथ नाम क्यों संघर्ष करते हैं ?? –
यह स्कूल के लिए एक परियोजना है। –
कभी नहीं, इसे काम कर रहा है। मेरी मूल पोस्ट संपादित की। –